PDA

View Full Version : how do I get datefield to require a certain format when the user is inputing via text



w_goldman
13 May 2016, 10:16 AM
I do not want the number 05, for example to convert to the 5th of the current month when the user leaves that datefield textbox. I want it to be an error or do nothing, but do not change what the user entered.

I tried adding a blur listener, but the value entered is already gone when it gets called (I get 05/05/2016 presently).


Ext.application({ name: 'Fiddle',


launch: function() {

var aDateField =
{
text: 'Date',
xtype: 'datefield', // the column type
format: 'm/d/Y', // the displayed format
submitFormat: 'm/d/Y'
};

Ext.create('Ext.panel.Panel', {
renderTo: document.body,
title: 'Test',
items: [
aDateField
]
});
}
});

w_goldman
13 May 2016, 10:52 AM
btw if you enter just 5 (not 05) it does what I want and does not modify the entered value.

w_goldman
13 May 2016, 11:10 AM
btw the change listener works differently in 4.2.1 (versus 6), which does not really impact my issue directly. In 6 the change listener is called when the field entry is valid AND the date field loses focus, in 4.2.1 it is called on each key stroke change.

Gary Schlosberg
13 May 2016, 1:32 PM
Can you configure a validator (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Date-cfg-validator) for the datefield?

w_goldman
16 May 2016, 11:47 AM
Can you configure a validator (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Date-cfg-validator) for the datefield?

I do not believe a Validator is going to help.

For example if the user is in the process of entering 05/05/2016, but has only entered 05 what would the validator do? Anyway at that point the entry is not invalid, the user has not completed entry.

Gary Schlosberg
16 May 2016, 2:01 PM
Unless you've configured the validateOnChange (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Date-cfg-validateOnChange) config to false, it should validate on each key stroke. Perhaps your validation function could account for that?

w_goldman
17 May 2016, 8:06 AM
Unless you've configured the validateOnChange (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Date-cfg-validateOnChange) config to false, it should validate on each key stroke. Perhaps your validation function could account for that?

so what should it do when the user has enter 05, with the intent to complete it with 05/05/2017?

Furthermore as I stated earlier if the user enters 05, the value sent to change is the 5th of the current month, i.e. 05/05/2016, I really have no idea what the user entered whether it was 05 or 05/05/2016 (field.getRawValue() returns 05/05/2016 when the user enters 05).