Continued from Creating Mobile Apps with Sencha Touch 2 – Part 1
Since the editing and creating note screen going to be same, so we can share the same screen.
app/view/NoteEditor.js
Ext.define("SenchaNote.view.NoteEditor", {
extend: "Ext.form.Panel",
xtype: "noteeditor",
requires: ["Ext.form.FieldSet", "Ext.field.Select"],
initialize: function() {
var toolbar = {
xtype: "toolbar",
docked: "top",
title: "Add Note",
items: [
{
xtype: "button",
ui: "back",
text: "Back",
handler: this.onBackTap,
scope: this
},
{ xtype: "spacer" },
{
xtype: "button",
ui: "confirm",
text: "Save",
handler: this.onSaveTap,
scope: this
}
]
};
this.add([
toolbar,
{
xtype: "fieldset",
defaults: { //this set default value to every items added
xtype: "textfield"
},
items: [
{
name: "content",
label: "Content"
},
{
name: "categoryid",
label: "Category",
xtype: "selectfield",
store: "Category",
displayField: "name",
valueField: "id"
}
]
}
]);
},
config: {
listeners: {
show: function() { this.onShow(); }
}
},
onShow: function() {
if (this.getRecord().phantom) {
this.items.get(0).setTitle("Add Note");
} else {
this.items.get(0).setTitle("Edit Note");
}
},
onSaveTap: function() {
//fire event to controller
},
onBackTap: function() {
//fire event to controller
}
});
Here we need to use the Ext.form.Panel, and import the Ext.form.FieldSet and Ext.form.Select. Then the usual stuff, create a toolbar, docked it on the top, give it a title “Add Note”, and add a back button and a save button on it, and assign handler to both buttons.
After creating the object of toolbar, add it to the screen using this.add just like the search bar (do it in initialize because we need to add the handler to the buttons.
In the this.add, we add another item on the fly (I mean without creating using the var ), use the built in xtype fieldset, note that there is a new thing, defaults, it simply means what ever item we configure later on will using the setting in defaults, unless specified otherwise.
So here I set default type to xtype:textfield, so that all item will default to a textbox. In the items, I need the content textbox. Note the { name: “price”, label :”Price”, xtype: “numberfield” } I commented is to show that we can override the defaults by specifying the xtype, and the numberfield here will allow the mobile browser display numeric keyboard, which made data entry easier.
Read more ... →