PDA

View Full Version : Passing VTypes the current Formfield



chaostimmy
20 Jul 2012, 8:03 AM
Heya, i want to use VTypes but need the Formfield that is currently being validated..

in the VType example (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.VTypes (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.form.field.VTypes)) is shown the following:


// custom Vtype for vtype:'time'
var timeTest = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
Ext.apply (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext-method-apply)(Ext.form.field.VTypes (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.form.field.VTypes), {
// vtype validation function
time: function(val, field) {
return timeTest.test(val);
},
// vtype Text property: The error text to display when the validation function returns false
timeText: 'Not a valid time. Must be in the format "12:34 PM".',
// vtype Mask property: The keystroke filter mask
timeMask: /[\d\s:amp]/i
});


But when I try that, the field argument is always empty.... :(

solutions? suggestions?

scottmartin
21 Jul 2012, 8:52 AM
This seems to work, please check on your end.




// custom Vtype for vtype:'time'
var timeTest = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
Ext.apply(Ext.form.field.VTypes, {
// vtype validation function
time: function(val, field) {
console.log(field);
return timeTest.test(val);
},
// vtype Text property: The error text to display when the validation function returns false
timeText: 'Not a valid time. Must be in the format "12:34 PM".',
// vtype Mask property: The keystroke filter mask
timeMask: /[\d\s:amp]/i
});

Ext.onReady(function(){

Ext.create('Ext.form.field.Text', {
fieldLabel: 'Departure Time',
name: 'departureTime',
vtype: 'time', // applies custom time validation rules to this field
renderTo: Ext.getBody()
});

});


Regards,
Scott.

chaostimmy
23 Jul 2012, 1:46 AM
oh nooo..

why does Ext.log(field) say "empty string"
and
console.log(field) show the object??

:(

thank you very much for helping me finding the problem! :)=D>