PDA

View Full Version : Ext.MessageBox.prompt() Resetting maxLength



Cliff
18 Mar 2011, 1:39 PM
Yesterday I was told to put a limit of 25 on the input field for the Ext.MessageBox.prompt() (i.e. set maxLength). There is no config for this, but this is how I went about it:


// This returns the dom ref for the input field on the prompt window ...
var inputDom = Ext.MessageBox.getDialog().body.child('input').dom;
// Next, I pull the pre-existing maxLength attrib because I'll need to set it back later ...
var originalMaxLen = inputDom.maxLength;
// Changing the axLength to 25 this way works fine ...
inputDom.maxLength = 25;
// Now run the window ...
Ext.MessageBox.prompt(
'My Title',
'Please enter a new Name:',
function(btn, text) {
// In all cases, put the original maxLength back to the way it was ASAP ...
inputDom.maxLength = originalMaxLen;
if (btn == 'ok') {
// do something ...
}


I understand that because Ext.MessageBox is a singleton, I must set back any properties that I change ASAP. This is the point of setting maxLength back to the original value in the first line of the callback function. Unfortunately I can't use the original value from inputDom.maxLength because it is -1. When I set it back to -1, it causes the field to not allow any user input the next time that prompt() is used. I don't want to set maxLength back to an arbitrary number like 255. Does anyone have a better idea? Why is maxLength defaulted to -1? Does -1 represent something in that case?