PDA

View Full Version : Setting Max Length in ComboBox



nitinfuture
3 Aug 2010, 9:35 AM
Hi,
I am setting the max length of the combo box, which is the property of the text field. The behaviour which it is showing is that it allows the user to put character after the max length and on tab out or on blur it is showing warning message.

But what I want is that I don't even want to allow the user to put character after the max length is covered. How can I achieve this in combo box.

Any help will be appreciated.

Regards,
Nitin

FCTim
3 Aug 2010, 6:39 PM
There is an example in the API doc. (http://www.sencha.com/deploy/dev/docs/?class=Ext.form.ComboBox). You need to use the autoCreate config to force the maxLength of the underlying dom(?) element.



var myField = new Ext.form.NumberField({
id: 'mobile',
anchor:'90%',
fieldLabel: 'Mobile',
maxLength: 16, // for validation
autoCreate: {
tag: 'input',
type: 'text',
size: '20',
maxlength: '10'
}
});

Colin Alworth
6 Aug 2010, 10:59 AM
FCTim has the right idea, but as you are talking about Ext-GWT and not ExtJs, you'll need to modify the underlying input element. Something like

comboBox.getInputEl().setElementAttribute("maxlength",50);
should do the trick. Remember to make this post-render, either by putting it in a listener for the Events.Render event, or by subclassing the Component and putting it in afterRender().

FCTim
6 Aug 2010, 11:07 AM
Whoops. I just clicked it from a RSS feed and didn't notice what forum is was under. :-)