Hello much more knowledgeable developers of the world,
My question as asked in the title is that if it is possible to delete the invalid values entered that are being validated by Parsely.js automatically while keeping the parsly.js message? I've accomplished this to a degree with the following library I've created which really is just a library full of regular expressions that replaces the improper characters by deleting them. A few examples of what that library looks like is here:
//Regex to determine if the string is Alphanumeric (Both letters and numerals). Deletes any values that don't fit the criteria.
function hasNumbersAndLetters(input)
{
var regex = /[^a-zA-Z0-9\s-,]/gi;
input.value = input.value.replace(regex, "");
}
//Compares the string to a regex looking for numbers only, will remove any values that don't fit the regex.
function onlyNumbers(input)
{
var regex = /[^0-9]/gi;
input.value = input.value.replace(regex, "");
}
These functions do in-fact work with the onblur event immediately after typing an improper value in the form being validated but cancel out the parsely.js message indicating why that is happening through its validation for being alphanumeric as an example.
This is an example of what one of my inputs looks like:
<input type="text" id="username" name="username" onblur="hasNumbersAndLetters(this)" data-parsley-type="alphanum" required="" value="<?php if (!empty($username)) echo $username; ?>" />
If you can point me in the right direction it is appreciated.
Parsley has not been designed with this in mind, and form validation in general does not work this way. You may be able to get away with this by listening to the
field:errorevent and making your changes then, but the interface will suffer. I strongly recommend following community standards which do not "autocorrect" the inputs.