Disable keyup validation after ParsleyFailedOnce
See original GitHub issueI 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:
- Type in alphabets in the input field, the focus out.
- Parsley will show error
- Remove invalid input, type in numbers
- 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:
- Created 7 years ago
- Comments:8
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FYI, it validates on
input
, not onkeyup
. 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 interceptingkeypress
, and aninput
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)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.