Skip to content

Instantly share code, notes, and snippets.

@euforic
Created April 24, 2012 23:31
Show Gist options
  • Save euforic/2484573 to your computer and use it in GitHub Desktop.
Save euforic/2484573 to your computer and use it in GitHub Desktop.
Easy Evented Titanium Forms With Shimmy
//Requires [Shimmy](https://github.com/Xogix/TiLibrary/tree/master/Shimmy)
//Simple forms with Shimmy
var shimmy = require('/Shimmy')
, ui = shimmy.UI
, _ = shimmy._;
var win = ui.Window();
var form = ui.Form({
style: 'grouped' //Set Form/Table Style
, fields: [ //Input type defaults to textfield
{ name: 'Title', section: 'title', hint: 'Event Name', value: '', id:'title' }
, { name: 'Start', section: 'duration', hint: 'Start Time', value: '' }
, { name: 'End', section: 'duration', hint: 'End Time', value: '' }
, { name: 'Repeat', section: 'duration', hint: 'Repeat', value: '' }
, { name: 'Notes', section: 'notes', hint: 'Additional Notes', value: '', type:'textarea' }
]
});
// Input Event Listeners
form.on('Title.focus', function(e){ alert(e.source); });
form.on('Title.change', function(e){ alert(e.source); });
form.on('Title.blur', function(e){ alert(e.source); });
// Access Individual Form Fields
// Field Accessors default to name value if no id is set
form.fields.title.value = 'newvalue';
// Batch updates of Form Fields and other field attributes
form.setValues({Title:{ value:'Awesome', data:'HIDDENDATA'} });
//Toggle Ability to Edit Form Fields
form.editable(false);
// Form input Event Listeners
form.on('title.focus', function(e){ alert(e.source); });
form.on('Start.change', function(e){ alert(e.source); });
form.on('Repeat.blur', function(e){ alert(e.source); });
// Form Table Proxy Event Listeners
form.onProxy('click', function(e) {
// Get Form Values
var formVals = form.getValues();
alert(formVals);
});
win.add(form);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment