Ext.form.NumberField: Combining maxLength and maxValue

Filed Under mercialleasing.com |

  • Dear ExtJS-Team,

    I'm trying to combine the maxLength and maxValue parameters, but it doesn't seem to work. Example:


    customer_response_offer_ok_no_option_remind_days = new Ext.form.NumberField({
    width: '40',
    hideLabel: true,
    value: 2,
    maxValue: 200,
    minValue: 1,
    maxLength: 3,
    name: 'offer_ok_no_option_remind_days'
    });


    The reason for that is that my customer wants a hard limit when entering numbers (some of his clients seem to ignore the red lines and the message for any reason).

    Regards,
    Timo


  • Exploring the validator functionality further. You'll find the solution there.


    Ext.onReady(function(){
    var simple = new Ext.FormPanel({
    title: 'Simple Form',
    width: 350,
    bodyStyle:'padding:5px 5px 0',
    width: 350,
    defaults: {width: 230},
    items: [{
    xtype : 'numberfield',
    fieldLabel: 'Number',
    validator : function(value){
    if(value.length > 3){
    this.setValue(value.substr(0,3));
    }
    return true;
    }
    }
    ]
    });

    simple.render(document.body);
    });


  • Post it please, together with a showcase, to Bugs forum if you think it's a bug or to Missing or incorrect docs thread if you think it's a documentation flaw.


  • Dear Joshua,

    I want it exactly as someone would expect it:

    - Limit the length to 3 characters. The end user has no way to enter more than 3 characters in this field. Right now, the user can enter a value larger than that (e.g. he could enter 0100), which would technically meet the requirement of a maximum value of 200.
    - Limit the maximum value to 200.

    Right now, the numberField doesn't limit the input length, like the textfield does.

    Regards,
    Timo


  • While what you posted might work, this is either a bug within ExtJS or a documentation issue. There's no word in the documentation for Ext.form.NumberField that these options exclude each other or that maxLength is completely useless (I haven't tested this yet).

    regards,
    Timo


  • Hi Timo,

    What exactly are you trying to do? Limit the numeric value between max and min parameters? minValue & maxValue will do the trick. maxLength then become irrelevant.

    To limit them to a particular number of chars (possibly to echo the char length in your database), use maxLength.

    It is also possible to do an additional check when the field loses focus. Check out validator (http://extjs.com/deploy/dev/docs/?class=Ext.form.NumberField&member=validator).

    Cheers,
    Joshua







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Ext.form.NumberField: Combining maxLength and maxValue , Please add it free.

    Comments