I have a datefield in a form like this:
{
xtype:'datefield',
name:'order[date]',
id:'dato',
format:'d-m-Y',
allowBlank: false,
cls:'inpu开发者_JS百科t_single',
emptyText:'dd-mm-yyyy',
minValue:new Date().add('d',-1),
onFocus: function(){
if (this.el.getValue() == 'dd-mm-yyyy') {
Ext.getCmp('dato').setValue('');
}
},
msgTarget:'side',
minText:'Must be future date',
validationEvent:false
}
Now my problem is that i want to force user to use dd-mm-yyyy format, but with the above code the user can type 01102010 for 1st of october 2010.
I thought that format:'d-m-y' would force this, but it dont.
Validation should be clientside.
So either the field should reformat the date to 01-10-2010 onblur or it should just not allow other formats than dd-mm-yyyy. Last version is prefered :)
Thanks in advance!
Just did a bit more researching in the api documentaion and found
altFormats:'d-m-Y',
That solved the problem. Now it will only accept the above format.
You can create and use your own VType and including it you can check whether a user has entred a valid date or not. Besides it offers you more reusability furhter. For refernce:http:docs/#!/api/Ext.form.field.VTypes
精彩评论