Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#12977 closed defect (fixed)

dijit.form.*: inconsistency in treating required flag and in docs on validating forms.

Reported by: zimnyx Owned by: bill
Priority: high Milestone: 1.7
Component: Dijit - Form Version: 1.6.0
Keywords: Cc:
Blocked By: Blocking:

Description

Only one dijit.form widget (ValidationTextBox?) define method _setRequiredAttr. This method calls _refreshState() which sets widget state based on required flag among others. The side effect is that only this widget returns up-to-date value of property 'state' after form is loaded.

Here are two examples proving inconsistency; both fields are empty after form is loaded:

Form A:

  • ValidationtextBox (required=true)
  • Select (required=false)
    formA.isValid()
    >>> false # it's because ValidationtextBox.get('state') == 'Incomplete', which is OK
    

Form B:

  • ValidationtextBox (required=false)
  • Select (required=true)
    formB.isValid()
    >>> true # both Select.get('state') and ValidationtextBox('state') returned "", and for Select this value is not expected. 
    

Docs states:

http://dojotoolkit.org/reference-guide/dijit/form.html
Dijit provides hooks so you can either disable the submit button, or popup an error message when the user tries to submit, or even focus on the invalid field.

Disabling submit button until form is ready to submit is not possible with Select input, because empty Select(required=True), initially returns state "", which means value is valid and ready to send, which is just not true.

Docs also states:

http://dojotoolkit.org/api/1.6/dijit/form
dijit.form.Form.validate()
returns if the form is valid - same as isValid

It's not true as formB.isValid() and formB.validate() will return opposite values on this form.

Change History (4)

comment:1 Changed 8 years ago by Douglas Hays

Owner: changed from Douglas Hays to bill
Type: enhancementdefect

This seems to be a regression in 1.6 possibly linked to the "watch" implementation. I would think that _FormMixin.js's isValid should look something like (closer to the 1.5 implementation):

var valid = true;
dojo.forEach(this.getDescendants(), function(widget){
        valid = valid && (widget.disabled || !widget.isValid || widget.isValid());
});
return valid;

refs [23213]

comment:2 Changed 8 years ago by bill

Sounds like the issue is limited to Select? I see that Select doesn't update Select.state according to required status, but everything else w/a required flag extends ValidationTextBox.

comment:3 Changed 8 years ago by bill

Resolution: fixed
Status: newclosed

(In [25657]) Fixes to Select validation:

  • Make Select.state either "" or "Incomplete", not "Error", to match behavior of other form widgets.
  • Update Select.state according to Select.required and Select.disabled. (The state is "Incomplete" whenever required == true, disabled == false, and no value is selected.)
  • Fix display of validation tooltip so it appears on the second focus, same as other form widgets work.

Fixes #12977,#12978 !strict.

comment:4 Changed 8 years ago by bill

Milestone: tbd1.7
Note: See TracTickets for help on using tickets.