-
20 Jul 2012 8:03 AM #1
Answered: Passing VTypes the current Formfield
Answered: Passing VTypes the current Formfield
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) is shown the following:
But when I try that, the field argument is always empty....Code:// 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) { 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 });

solutions? suggestions?
-
Best Answer Posted by scottmartin
This seems to work, please check on your end.
Regards,Code:// 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() }); });
Scott.
-
21 Jul 2012 8:52 AM #2Sencha - Support Team
- Join Date
- Jul 2010
- Location
- Houston, Tx
- Posts
- 7,185
- Vote Rating
- 194
- Answers
- 433
This seems to work, please check on your end.
Regards,Code:// 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() }); });
Scott.
-
23 Jul 2012 1:46 AM #3
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!



Reply With Quote