jqGrid - Password confirmation
Asked Answered
L

1

0

I want to do a simple thing: I want to compare the data from two fields on input. I mean: the user will fill a field with his password and there will be another field asking him to fill his password again. I want to compare these two datas to see if they match.. My problem is that I don't know how to retrieve the data from the confirmation field to compare it. Relevant part of the code is here (confirmaSenha is the confirmation field):

{name:'senha', width:80, sortable:true, editable: true, hidden:true, edittype:'password', editrules:{edithidden:true, required:true, custom:true, custom_func:validaSenha}},
{name:'confirmaSenha', width:80, sortable:true, editable: true, hidden:true, edittype:'password', editrules:{edithidden:true, required:true}},

function validaSenha(value, colname){               
    if (colname=='senha' && value == HOW_DO_I_GET_DATA_FROM_CONFIRMATION_FIELD?) {
        return [true, ""];
    }
    else {
        return [false, ""];
    }
}

EDITED

if ((colname == 'senha') && (value == $('#tr_confirmaSenha').val())) {
        alert('true');
        return [true, ""];
    }
    else {          
        var senha = $("#tr_confirmaSenha").val();                
        alert(senha);
        $("td.editmsg", 'FrmGrid_grid').html("Senhas diferentes.");
        return [false, ""];
    }
}

Thanks in advance.

Latoyia answered 28/11, 2013 at 11:47 Comment(4)
As an aside, what's FALSE? (As compared to false...)Gastroenterology
I edited it now to "false". Still now knowing how to retrieve data from the field...Latoyia
use JQuery $('class or id') of your confirm field name and compare it with that. I would add row id as data-toconfirm="idofsamerow+somename" and use that logic to retrieve anything.Polysyllable
I tried to do what you said but .val() is displaying an empty string. I edited the post to show you my codeLatoyia
C
0

According to the first post in the discussion section of http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules

You can reference the actual input boxes by their name. In his example he is referencing the input in the dataevents option of editOptions, but you should be able to do the same in your custom validator, I think.

editoptions: { size: 1,
               dataUrl: 'Includes/tblJobSelect.php',
               dataEvents: [
                  {  type: 'change',
                     fn: function(e) {
                        $('input#Job_Number').val(this.value);
                     }
                  }
               ]
},

here

  $('input#Job_Number')

references the editable input type for a column named Job_Number

In your example, you should be able to reference confirmaSenha as

  $('input#confirmaSenha')

Try using firebug or something similar to see what the id of the input element is/are. Also, you might want to consider what happens if more than one row is editable. If multiple rows are editable at the same time this selector

  $('input#confirmaSenha')

would give you more elements than I think you are expecting. A better option is to reference the row in question directly, but unfortunately it's kind of hard to do that in this situation because you don't actually have a reference to the validating input or its row via the custom validator function. If this a problem for you, you should consider disabling edits on multiple rows at a time, or figuring out a way to determine on which row the input exists.

Cockle answered 29/11, 2013 at 13:38 Comment(2)
ok.. I looked out for their names on html and the function is working now, but.. how can I customize an error message? I want to show something like "Passwords don't match."Latoyia
return [false, "Passwords don't match"];Cockle

© 2022 - 2024 — McMap. All rights reserved.