Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#8977 closed defect (fixed)

dijit.form.Form.isValid return Numer 0 instead true and 1 instead false

Reported by: niquola Owned by: bill
Priority: high Milestone: 1.3
Component: Dijit - Form Version: 1.3.0b3
Keywords: Cc:
Blocked By: Blocking:

Description

here form example

<form dojoType="dijit.form.Form" dojoAttachPoint="form">
    <p dojoAttachPoint="splashNode" class="${baseClass}Splash"></p>
    <p>
    <label class="${baseClass}Label" for='summary'>Summary:</label>
    <input class='' dojotype='dijit.form.ValidationTextBox' name='summary' style='width:100%;' title='summary' type='text'
    required='true' invalidMessage="Summary is required."/>
    </p>
    <p>
    <button class="${baseClass}Button" dojoAttachPoint="submitButton" dojotype='dijit.form.Button' >Submit</button>
    </p>
  </form>

and handling

    dojo.connect(this.submitButton, 'onClick',
    function() {
      console.log(form.isValid()); // log 0 if field is not empty and 1 if empty
      }
    });

Change History (9)

comment:1 Changed 11 years ago by bill

That's true, is that a problem (and if so, why)?

comment:2 Changed 11 years ago by Adam Peller

Well, we could make it a boolean with just 2 additional chars (!!) and then add jsdoc to indicate that this function has a Boolean return value. Right now, I guess that's just supposed to be understood, and the user should be using truthy/falsey expressions to deal with the result. If we don't define isValid's return type, could that lead to trouble?

comment:3 Changed 11 years ago by niquola

the problem is not the type of returned value, but that the logic is wrong - 0 returned when form is valid is falsy!

comment:4 Changed 11 years ago by Adam Peller

Owner: set to Douglas Hays

yikes. How could we fix that without breaking compatibility? We might have to leave it as is and document it clearly.

comment:5 Changed 11 years ago by niquola

so should we treat this correct: if(form.isValid()==0){

submit form

}else{

warn user that form is not valid

} ???

comment:6 Changed 11 years ago by niquola

ups :( so should we treat this correct:

if(form.isValid()==0){
    //submit form
}else{
    //warn user that form is not valid
} 

???

comment:7 Changed 11 years ago by bill

Milestone: tbd1.3
Owner: changed from Douglas Hays to bill
Status: newassigned

Oh sorry, I broke this recently in [17106], will fix.

comment:8 Changed 11 years ago by bill

Resolution: fixed
Status: assignedclosed

OK, fixed in [17120], thanks for catching that. Will add a test for this to the unit test later.

comment:9 Changed 9 years ago by bill

Component: DijitDijit - Form
Note: See TracTickets for help on using tickets.