2

I have change password screen and i want Current Password and New Password should not be same is there a way to do this using parsley

i also try with following condition but get no luck.

data_parsley_notequalto = "#controlId"
ni3.net
  • 377
  • 4
  • 14
  • You would need to write a custom validator - have a look at the answer here http://stackoverflow.com/questions/19361050/parsley-js-custom-validator-not-equal-to – glendaviesnz Apr 09 '14 at 08:59

2 Answers2

4

This code worked well for me in many cases:

window.Parsley.addValidator("notequalto", {
    requirementType: "string",
    validateString: function(value, element) {
        return value !== $(element).val();
    }
});

You can use it like this:

<input type="text" id="test1" data-parsley-required>
<input type="text" id="test2" data-parsley-required data-parsley-notequalto="#test1" data-parsley-notequalto-message="These two fields must not be identical!">
Dieter Schmitt
  • 471
  • 2
  • 8
0

I had the same question as you.

Then I found out you can create a custom validator.

Here's mine:

HTML:

<input type="text" id="myInput" data-parsley-notequalto="test" />

Add this before including parsley.js

window.ParsleyConfig = {
  validators: {
    notequalto: {
      fn: function (value, id) {
        return value !== $('#id').val();
      },
      priority: 32
    }
  },
  i18n: {
    en: {
      notequalto: 'This value not equal to %s'
    }
  }
};

This will check if the value of #myInput is equal to 'test'. If equal it will display the error message specified.

jwpfox
  • 5,124
  • 11
  • 45
  • 42
Frenker
  • 13
  • 4