PDA

View Full Version : Message Box validation of input (modification to disable buttons)



para
29 May 2007, 10:02 AM
Howdy,

I'm trying to modify the MessageBox to allow for a "validator" function. Essentially, as text is typed into the prompt, I want it to call the validator function (after each keystroke).
The validator function determines whether the input is valid or not (by whatever means), and returns true/false.
If it returns false, I want the OK button to be disabled.

I've copied and overwritten the MessageBox.js (temporarily... It will become an extension).
I've added keylisteners to the textBoxEl, but upon doing so it no longer puts text into the box. It does call the validator assigned to the MBox.




var handleValidation = function(){
var t = 0; // will call the associated validator here
};





dlg.addKeyListener(allKeys, function(){
if(dlg.isVisible() && opt && opt.buttons){
handleValidation();
}
});


I think this would be a very cool thing to add in if it can be done in a generic enough way.

para
29 May 2007, 11:41 AM
I may have prematurely posted... I'm well on my way to solving this.
I'll post again if/when I get it done.

para
30 May 2007, 7:21 AM
I feel odd replying to my own posts... It's like a terrible blog.

Anyways, I completed my modification to the MessageBox and will be posting my solution soon. I think it may actually be nice/pretty/functional enough to add to the library. We'll see.

yanidp
3 Jun 2007, 6:19 AM
Hello para, you don't talk by self. When you post your solution. Thanks

umut
5 Jun 2007, 4:26 AM
So, how about that solution para?

para
5 Jun 2007, 1:07 PM
I will post it...My company is debating (defining) it's policies on open-source contributions. It will be posted within a week or two, but I do have to wait for the policy to become official.
I'm also having time to refine it a bit here and there.

para
18 Jun 2007, 6:28 AM
Here's my solution...
You have to define a "validator" function to handle the validation. It can return True/False/String/[String]. If a String or [String] is returned, the string(s) will be displayed as error messages and the OK/YES buttons will be disabled. It validates 200 ms after each keystroke (or a user defined time of 'vtimer'). There is no way to get around it by clicking the OK button very quickly because it does a final validation if there is one pending.
Let me know what you think.