Search code examples
javascriptextjsdatefield

How to prevent autofill on datefield in ExtJS?


When date value is not valid, Ext tries to make a correct date. For example, if type 21 in datefield in KitchenSink, press Tab, it will be date 10/21/16(http://examples.sencha.com/extjs/6.0.2/examples/kitchensink/#form-fieldtypes)

How to disable this behaviour?


Solution

  • There is a config on the date field called altFormats that will reformat the value the user enters according to a list of formats separated by |. The default is:

    m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d|n-j|n/j

    but if you set altFormats: null the behaviour you want to disable will no longer function. You may want to keep some of these formats and just delete the ones that you do not want to be converted to valid dates.

    See this fiddle https://fiddle.sencha.com/#fiddle/1jed