Quantcast

Why ValidationTextBox validation doesn't highlight the box?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Why ValidationTextBox validation doesn't highlight the box?

carek
Hi. I've got ValidationTextBox in my code created like this:

<div dojoType="dijit.form.ValidationTextBox" required="true" dojoAttachPoint="tabTitle"></div>

and my question is how can I made it validated programatically? (I want it to be highlighted when user doesn't fill this field and click submit)

I tried to call validate(), validator() and isValid() on it, but it doesn't work...
And one more thing what do I need to do if I want it to be validated by my own function?
I mean I overrided validator:

this.tabTitle.validator = dojo.hitch(this, this._titleValidation);

_titleValidation: function() {
                if (this.tabTitle.get("value").length > 0) {
                        if (!this.tabTitle.get("disabled") && dojo.indexOf(this.titles, this.tabTitle.get("value")) != -1) {
                                return false;
                        }
                        return true;
                }
               
                return false;
        },

it returns proper boolean value but the field still isn't highlighted when I call validate isValid or validator...
Overriding isValid doesn't work as well
please help I wasted so much time on this already :(

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why ValidationTextBox validation doesn't highlight the box?

Rouben Meschian
The validation widgets can be used inside a dijit.form.Form.  Then, all you have to do is call validate on the form and it will return true if all the widgets inside of it are true, and if false then it will find the first invalid widget and focus it.  If you want to do this yourself, without the use of a dijit.form.Form, then let's look at the validate method in _FormMixin:

validate: function(){
                        // summary:
                        // returns if the form is valid - same as isValid - but
                        // provides a few additional (ui-specific) features.
                        // 1 - it will highlight any sub-widgets that are not
                        // valid
                        // 2 - it will call focus() on the first invalid
                        // sub-widget
                        var didFocus = false;
                        return dojo.every(dojo.map(this.getDescendants(), function(widget){
                                // Need to set this so that "required" widgets get their
                                // state set.
                                widget._hasBeenBlurred = true;
                                var valid = widget.disabled || !widget.validate || widget.validate();
                                if(!valid && !didFocus){
                                        // Set focus of the first non-valid widget
                                        dojo.window.scrollIntoView(widget.containerNode || widget.domNode);
                                        widget.focus();
                                        didFocus = true;
                                }
          return valid;
          }), function(item){ return item; });
                },

If you have a set of widgets and you want to find the first invalid one and focus it, just rip out this code and replace the this.getDescendants() with your list of widgets.

Good luck
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why ValidationTextBox validation doesn't highlight the box?

carek
kindly thank You... Problem solved :)
Loading...