PDA

View Full Version : Validations in Sencha Touch, is not working. Please help me with this.



chinj
14 Oct 2010, 10:27 PM
Please check my code , my validation not working.


Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady : function() {

Ext.regModel('User', {
fields: [
{name: 'name', type: 'string'},
{name: 'email', type: 'string'},
{name: 'url', type: 'string'},
{name: 'skills', type: 'string'},
],
validations:[
{type:'length', name:'skills', min:40, max:150},
{type:'format', name:'email', matcher: /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/},
{type:'presence', name:'url'},
{type:'exclusion', name:'name', list:['admin']}
]
});
Ext.regModel('Contact', {
fields: ['firstName', 'lastName']
});

var groupingBase = {
tpl: '<tpl for="."><div class="contact"><strong>{firstName}</strong> {lastName}</div></tpl>',
itemSelector: 'div.contact',

singleSelect: true,
grouped: true,
indexBar: true,

disclosure: {
scope: 'test',
handler: function(record, btn, index) {
alert('Disclose more info for ' + record.get('firstName'));
}
},

store: new Ext.data.Store({
model: 'Contact',
sorters: 'firstName',

getGroupString : function(record) {
return record.get('firstName')[0];
},

data: [
{firstName: 'Tommy', lastName: 'Maintz'},
{firstName: 'Ed', lastName: 'Spencer'},
{firstName: 'Jamie', lastName: 'Avins'},
{firstName: 'Aaron', lastName: 'Conran'},
{firstName: 'Dave', lastName: 'Kaneda'},
{firstName: 'Jay', lastName: 'Robinson'},
{firstName: 'Zed', lastName: 'Zacharias'}
]
})
};


pan = new Ext.Panel({
cls:'dummmy',
fullscreen:'true',
htmlText:'dummy',
style:'background:white !important',
layout:'card',
items:[

new Ext.List(Ext.apply(groupingBase, {
floating: true,
width: 350,
height: 370,
centered: true,
modal: true,
hideOnMaskTap: false,
listeners:{ "itemtap": function(DataView,index,item,e){
var rec = DataView.getStore().getAt(index).data;
var fullName = rec.firstName+' '+rec.lastName;
//pan.body.setHTML(fullName);
//console.info(pan);
pan.setCard(1,{type:'slide',direction:'left'});
//console.info(pan.getComponent(1).getComponent(0).getComponent(3));
Ext.getCmp('selectBox').setValue('-1');
}
}
})),
{
dockedItems:[
{
xtype:'toolbar',
dock:'top',
items:[{
xtype:'button',
ui:'back',
text:'back',
handler:function()
{
pan.setCard(0,{type:'slide',direction:'right'});
}
},
{
xtype:'button',
text:'Reset Position',
handler:function()
{
Ext.getCmp('selectBox').setValue('technical');
}
}
,
{
xtype:'button',
text:'Load Model',
handler:function()
{
var newForm = Ext.ModelMgr.create({
'name' : 'Akura',
'password': 'secret',
'email' : 'saru@extjs.com',
'url' : 'http://extjs.com',
'skills' : 'C,C++'
}, 'User');
Ext.getCmp('myForm').loadModel(newForm);

}
}
]
}
],

xtype:'form',
id:'myForm',
items:[
{
xtype:'fieldset',
items:[{
xtype:'textfield',
name:'name',
label:'Name',
placeHolder:'Enter Name',
required:'true',
showClear:'true'
},
{
xtype: 'emailfield',
name:'email',
label:'Email',
placeHolder:'Enter Email Address'
},
{
xtype:'urlfield',
name:'url',
label:'Url',
placeHolder:'Enter Url'
},
{
xtype:'select',
name:'position',
label:'Position',
id:'selectBox',
value:'-1',

options:[{
text:'Technical',
value:'technical'
},
{
text:'Student',
value:'student'
},
{
text:'Slave',
value:'slave'
}
]
},
{
xtype:'textarea',
name:'skills',
label:'Skills'
}
]

}
]
}

]




});


/*if (!Ext.is.Phone) {
;
}
else {
new Ext.List(Ext.apply(groupingBase, {
fullscreen: true
}));
}*/
}
});