Password verification in dojo

I want to verify that the two passwords are the same using Dojo.

Here is the HTML that I have:

<form id="form" action="." dojoType="dijit.form.Form" / >

<p> Password: > ><input type="password"
name="password1"
id="password1"
dojoType="dijit.form.ValidationTextBox"
required="true"
invalidMessage="Please type a password" /
</p

<p> Confirm: > ><input type="password"
name="password2"
id="password2"
dojoType="dijit.form.ValidationTextBox"
required="true"
invalidMessage="This password doesn't match your first password" /
</p

<div dojoType="dijit.form.Button" onClick="onSave"> Save </div>

</form > Code>

Here is the JavaScript that I still have:

var onSave = function() {
if(dijit.byId('form').validate()) { alert('Good form'); }
else { alert('Bad form'); }
}

Thank you for your help. I could do it in pure JavaScript, but I'm trying to find a way for Dojo to do this.

+3
source share
3 answers

It will help you much closer.

  • setting intermediateChanges = false saves the validator that is executed each time a key is pressed.
  • The dijit check constraint object is passed to its validator. Use this to transfer another password entry.
  • dijit.form.Form isValid() , . , , . ; -)

:


function confirmPassword(value, constraints)
{
    var isValid = false;
    if(constraints && constraints.other)  {
        var otherInput =  dijit.byId(constraints.other);
        if(otherInput) {
            var otherValue = otherInput.value;
            console.log("%s == %s ?", value, otherValue);
            isValid = (value == otherValue);
        }
    }
    return isValid;
}
function onsubmit()
{
    var p1 = dijit.byId('password1').value;
    var p2 = dijit.byId('password2').value;
    return p1 == p2;
}

:


<p>Password: <input type="password"
    name="password1"
    id="password1"
    dojoType="dijit.form.ValidationTextBox"
    required="true"
    intermediateChanges=false
    invalidMessage="Please type a password" /></p>

<p>Confirm: <input type="password"
    name="password2"
    id="password2"
    dojoType="dijit.form.ValidationTextBox"
    required="true"
    constraints="{'other': 'password1'}"
    validator=confirmPassword
    intermediateChanges=false
    invalidMessage="This password doesn't match your first password" /></p>
+4

, Dojox, dojox.form.PasswordValidator.

http://docs.dojocampus.org/dojox/form/PasswordValidator

, !

+2

!

Dojo .

HTML :

<p > : <input type="password"
name="password2"
id="password2"
dojoType="dijit.form.ValidationTextBox"
required="true"
validator="return theSame(this, dijit.byId('password1'));"
invalidMessage="This password doesn't match your first password" /
> </p > >

.

JavaScript:

function(dojoTxt1, dojoTxt2) {
return dojoTxt1.getValue() == dojoTxt2.getValue();
}

, validator , .

+1

All Articles