Compare 2 textbox

Compare 2 textbox

xain819xain819 Posts: 15Questions: 4Answers: 1

Good Day to everyone.
so yea im using datatables with editor
what i want to do is when i create new user using the editor
i want to compare the two textbox which is the password field
(your typical registration)

                {
                    "label": "Password:",
                    "name": "user.Password",
                    "type:" "password"
                }, {
                    "label": "Confirm Password:",
                    "name": "repassword",
                    "type:" "password"
                }

so the confirm password is only an extra textbox just to check if they match
now how can i do that in the Editor?
where if true only the 1st field will be inserted..

newbiee here.. :(

This question has an accepted answers - jump to answer

Answers

  • pansengtatpansengtat Posts: 66Questions: 26Answers: 1
    edited September 2014 Answer ✓

    This assumes that you already know what to do after comparing the two password fields, i.e. knowing how to save password into the database which includes encryption.

    editor.on('preSubmit', function(e,obj,action){
        //--- Compare Password and Confirm fields. ---//
        if ( $.trim(obj.data.user.Password) === $.trim(obj.data.repassword) ) {
            //--- Do whatever you need to do here, like encryption/hashing ---//
        }
        //--- Check if both fields are empty. ---//
        else if ( $.trim(obj.data.user.Password) === '' && $.trim(obj.data.repassword) === '' )
        {
            //--- Do whatever you need to do here, like telling the user that there should be no blanks. ---//
        }
        //--- Throw error message, if the Password / Confirm fields don't match. ---//
        else
        {
            this.error('user.Password', 'Throw whatever error message you wish.');
            return false;
        }
    })
    
This discussion has been closed.