PDA

View Full Version : How to use datefield mask?



brunoferoleto
22 Aug 2012, 8:00 AM
Is there a way to use some typing mask in datefield?

I need this date format: dd/mm/yy.

I want that the user only to care about the number.
E.g.: The user types 12 and automatically a "/" is inserted and so on.

scottmartin
22 Aug 2012, 9:30 AM
Here is a type setup for time. You can modify it to fit your needs:




// 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.