Opened 10 years ago
Closed 10 years ago
#15432 closed defect (fixed)
TimeTextBox: Setting constraints does not update 'state' property
Reported by: | Paul Christopher | Owned by: | Douglas Hays |
---|---|---|---|
Priority: | undecided | Milestone: | 1.8 |
Component: | Dijit - Form | Version: | 1.7.2 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
Description
If you e.g. specify certain constraints like a min time in the page's ready function, the TimeTextBox's get('state') function still returns an empty string, although the entry is now invalid. Therefore the whole form is reported as valid although it is not valid anymore: form.get('state') returns an empty string, too. Only calling form.validate() forces a recalculation of the state properties.
Steps to reproduce the issue
Run the attached test case. The form is - as it is - invalid. TimeTextBox's value is 9, constraints.min is set to 10 in ready().
Press button "form.get('state')". This will get the form state via the form.get('state') method. Notice: The form is reported as valid, although it is not valid.
Press button "TimeTextBox.get('state')". This will retrieve the valid state of the TimeTextBox using TimeTextBox.get('state'). Again: the control is reported as valid (=an empty string) although it is - with the new constraints given - not valid anymore.
Now press button "form.validate()". The form is now reported as invalid, the TimeTextBox highlighted red.
Discussion
This is a problem since form.js onSubmit is
onSubmit: function(/*Event?*/ /*===== e =====*/){ // summary: // Callback when user submits the form. // description: // This method is intended to be over-ridden, but by default it checks and // returns the validity of form elements. When the `submit` // method is called programmatically, the return value from // `onSubmit` is used to compute whether or not submission // should proceed // tags: // extension return this.isValid(); // Boolean }
and _formMixin.js isValid is
isValid: function(){ // summary: // Returns true if all of the widgets are valid. // Deprecated, will be removed in 2.0. Use get("state") instead. return this.state == ""; }
Possible fix
Does ValidationTextBox.js _setConstraintsAttr simply needs calling isValid like so??
_setConstraintsAttr: function(/*Object*/ constraints){ if(!constraints.locale && this.lang){ constraints.locale = this.lang; } this._set("constraints", constraints); this._computePartialRE(); this.set('state', this.isValid()); }
Or is it maybe better to have a custom getter for the state property?
Attachments (3)
Change History (15)
Changed 10 years ago by
Attachment: | testForm.html added |
---|
comment:1 Changed 10 years ago by
Changed 10 years ago by
Attachment: | [CLA]patch01.txt added |
---|
Changed 10 years ago by
Attachment: | [CLA]patch01.diff added |
---|
comment:3 Changed 10 years ago by
Milestone: | tbd → 1.8 |
---|---|
Status: | new → assigned |
comment:5 Changed 10 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Except that it causes a failure in the beforeFocus test of ValidationTextBox.html (tested on IE8).
_AssertFailure: assertEqual() failed: expected Incomplete but got
It also causes 3 failures in Form_state.html (again on IE8).
And finally, a failure in !FilteringSelect_mouse.html.
comment:6 Changed 10 years ago by
Fixes #15432. Run _refreshState in ValidationTextBox.js on startup() after all initial _set*Attr methods have run instead of after each.
comment:11 Changed 10 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I had some time to look at the code now. I think _setConstraintsAttr simply needs to call _refreshState (as _setRequiredAttr and _setDisabledAttr already does), see patch attached.