jqGrid - Password confirmation

℡╲_俬逩灬. 提交于 2019-12-25 02:43:18

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/20265384/jqgrid-password-confirmation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!