jeudi 19 février 2015

How to make a number field optional AND have min and max validation?

I am using Sencha Architect 3.1.0 and ExtJS 5.0.

Objective:


I want a number field in the UI to be optional, but if a value is specified, it must be within a certain range.


Background:


It seems as though if I specify a minValue in the number field, it assumes that it's a required field, regardless of "allowBlank: true" or "allowNull: true". Specifying a "minValue" should not automatically make it required. Seems odd.


Also, in Sencha Architect, I don't seem to have an option to specify a Range validation on the model field. How can I add this?


I have a model with an int field as such:



Code:



{
type: 'int',
allowNull: true,
name: 'intField'
}

I have the form field specified as follows:

Code:



{
xtype: 'numberfield',
width: 400,
fieldLabel: 'Number must be between 1 and 50 (if specified)',
name: 'intField',
allowOnlyWhitespace: false,
allowDecimals: false,
allowExponential: false,
maxValue: 50,
minValue: 1
},

How can I make this work?

Thanks!






How to make a number field optional AND have min and max validation?

Aucun commentaire:

Enregistrer un commentaire