PDA

View Full Version : Number field validation



kavyakn
2 Apr 2013, 9:52 PM
How do I check for existing value in a grid using the number fiield in EXTJS form ? i.e I have a store with records and whenever the user spins the number field the value of the field should be compared with the record values and if same then it should show the number filed as invalid . I am trying to do this using validator function of number field. But not working as expected.

Farish
2 Apr 2013, 10:53 PM
this should be possible using a validator. in the validator function, you need to compare the value (of the number field) with those of the corresponding field from all records in the store. if it matches any one, return false. if none matches, return true (valid value).

mtpillai
9 Apr 2013, 10:38 PM
i have done the same on an editor grid... please c the below code..


{
header: 'Sequence No.',
dataIndex: 'seqNo',
width:100,
editor: {
allowBlank: false,
maskRe:/([0-9])$/,
minLength:1,
maxLength:8,
enforceMaxLength:8,
listeners: {
'blur': function(t,ev,b){
var columnData = Ext.getCmp("editorGridPanel").getSelectionModel().getSelection()[0].data;
oldValue = columnData.seqNo;
newValue =t.getValue();
storeCount = gridStore.getCount();
for(i = 0; i< storeCount; i++){
gridOldSeqNos = gridStore.getAt(i).data['seqNo'];
if(oldValue!=newValue && newValue== gridOldSeqNos){
Ext.Msg.alert('Duplicate Stop Sequence Number Found!', " Sequence Number Already Exists");
t.setValue(oldValue);
}
}
if(newValue<=0){
Ext.Msg.alert('Warning!', "Road Sequence No cannot left as Zero");
t.setValue("");
}
}
}


}//Editor
}//column

here am using textfield as editor, instead u can use number field

try it =D>