question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable keyup validation after ParsleyFailedOnce

See original GitHub issue

I have a custom validation function that will fill up numbers to a length of 10. With ParsleyFailedOnce, the code that runs the prefix does not work. I want the validation to work only when there is focusout instead of keyup.

http://codepen.io/hanxue/pen/XdZRoE?editors=1011

To reproduce:

  1. Type in alphabets in the input field, the focus out.
  2. Parsley will show error
  3. Remove invalid input, type in numbers
  4. As soon as there is a keystroke, the validation code will run, causing the input field length to be > 10

For convenience, here is the code

<form id="demo-form" data-parsley-validate>
  <input type="text" id="card_number" name="card_number" class="form-control"        data-parsley-required="true" data-parsley-trigger="focusout" 
         data-parsley-required-message="You did not enter Card Number!"
         data-parsley-numeric=""
         data-parsley-zeroprefix=""
       />
  <input type="submit" class="btn btn-default validate" />
</form>
window.Parsley.addValidator('numeric', {
  validateString: function(value) {
    return !isNaN(parseFloat(value)) && isFinite(value);
  },
  requirementType: 'integer',
  messages: {
    en: 'Enter only numbers for Card Number.'
  }
});

window.Parsley.addValidator('zeroprefix', {
  validateString: function(value) {
    if(isNaN(parseFloat(value)) && isFinite(value)) {
      return false;
    }
    else if(value < 1) {
      return false;
    } else {
      if(value.length < 10) {
        var original_length = parseInt(10) - parseInt(value.length);
        var zero_prefix = "";
        for (var i = 0; i < original_length; i++) {
           zero_prefix = zero_prefix + 0;
        }
        $('#card_number').val(zero_prefix + value);
      }
      return true;
    }
  if(value.length < 10) {
    var original_length = parseInt(10) - parseInt(value.length);
    var zero_prefix = "";
    for (var i = 0; i < original_length; i++) {
       zero_prefix = zero_prefix + 0;
    }
    $('#card_number').val(zero_prefix + value);
    value = $('#card_number').val();
    if(value == '0000000000') {
      return false;
    }
  }
  },
  requirementType: 'integer',
  messages: {
    en: 'Card number cannot be all zeroes.'
  }
});

I have looked at #1003 and #955 as well as parsley documentation, I don’t see an option to disable validation for keyup() after ParsleyFailedOnce.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
marcandrecommented, Apr 11, 2016

FYI, it validates on input, not on keyup. In any case, I feel that you should not modify the field being validated in a custom validator, ever. That modification should be done before validation occurs, e.g. by intercepting keypress, and an input event should be fired (like discussed in #1076). In short, I do not consider this a bug, you should change how you are doing things (and probably use a standard masking library)

3reactions
gpgpublickeycommented, Jan 9, 2018

Hello guys, i have the same problem here and is not a input event triggered is a keyup event, im using parsley Version 2.0.7 and it is not possible update it. It’s possible to implement a workaround to override this keyup/input event attached by default by parsley? i need that my parsley errors only be displayed when focusout is triggered but after the first one, when you press any key the validations are triggered again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to disable jquery validation on keyup and focusout for 1 ...
I myself was in the same scenario. Below is the code which I used for it. $.validator.setDefaults({ onkeyup: function () { var originalKeyUp...
Read more >
validate plugin. How to disable auto validation on keypress ...
I wish to be able to disable the automatic validation for one field/element only after submission how can this be done?
Read more >
How to disable remote jquery validations on keyup
how to disable my jquery remote validation on keyup. i want to do remote validation on blur only. I had three tabs in...
Read more >
Documentation - jQuery Validation Plugin
You need to place error messages in the DOM and show and hide them when appropriate. You want to react to more than...
Read more >
Form validation using jQuery - GeeksforGeeks
Form validation is a process of confirming the relevant information entered by the user in the input ... classList.remove( "is-invalid" );.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found