PDA

View Full Version : How can i check the validation?



gigas01
27 Jul 2012, 7:22 AM
Hello, I want to make a valid check function when the user presses the button.

For example, the user didn't choose the end time like that.

can i get some sample codes to follow or an advice?

I only found version 3 extjs sample code :(

this is my code.




{
xtype: 'form',
name: 'scheduleForm',
url: 'http://localhost/ci_extjs_crud/index.php/user/addSchedule',
items: [{
xtype: 'fieldset',
height: 500,
width: 629,
title: 'Enter New Schedule',
items: [{
store: companyData,
//mode: 'local',
xtype: 'combobox',
fieldLabel: 'Company Name',
dataIndex: 'companyName',
displayField: 'companyName',
valueField: 'companyName',
name: 'companyName',
anchor: '100%'
},
{
store: activityData,
xtype: 'combobox',
fieldLabel: 'Activity Name',
dataIndex: 'activityName',
displayField: 'activityName',
name: 'activityName',
anchor: '100%'
},


{
xtype: 'datefield',
fieldLabel: 'Start Date',
format: 'Y-m-d',
anchor: '100%',
name: 'startDate'
},
{
xtype: 'timefield',
fieldLabel: 'Start Time',
format: 'H:i',
anchor: '100%',
name: 'startTime'
},
{
xtype: 'datefield',
fieldLabel: 'End Date',
format: 'Y-m-d',
anchor: '100%',
name: 'endDate'
},
{
xtype: 'timefield',
fieldLabel: 'End Time',
format: 'H:i',
anchor: '100%',
name: 'endTime'
},
{
xtype: 'button',
text: 'Save',
handler: function() {
this.up('form').getForm().submit();
Ext.Msg.show({
title: 'Status',
msg: 'Success!',
icon: Ext.MessageBox.INFO,
width: 300
});
//window.location.reload();
}
}]
}]
}

scottmartin
27 Jul 2012, 9:07 AM
You can use options like: allowBlank, vtypes, validate... check on the form level form.isValid, etc

There are many options depending on your requirement.

ex: vtype for phone:



Ext.apply(Ext.form.VTypes, {
phone: function(v) {
var phoneRegex = /^\d{3}-\d{3}-\d{4}$/;
return phoneRegex.test(v);
},
phoneMask: /[\d-]/,
phoneText: 'Invalid: ###-###-####'
});


Scott.