Skip to content

Instantly share code, notes, and snippets.

@axelav
Last active April 9, 2018 19:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axelav/8226707 to your computer and use it in GitHub Desktop.
Save axelav/8226707 to your computer and use it in GitHub Desktop.
I had a hard time finding documentation on configuring parsley.js. Here's what I've found you can configure.
// Parsley default config
$.fn.parsley.defaults = {
inputs: 'input, textarea, select',
excluded: 'input[type=hidden], :disabled',
trigger: 'change',
animate: true,
animateDuration: 300,
focus: 'first',
validationMinlength: 3,
successClass: 'has-success',
errorClass: 'has-error',
errorMessage: false,
validators: {},
showErrors: true,
messages: {
// parsley //////////////////////////////////////
defaultMessage: "This value seems to be invalid.",
type: {
email: "This value should be a valid email.",
url: "This value should be a valid url.",
urlstrict: "This value should be a valid url.",
number: "This value should be a valid number.",
digits: "This value should be digits.",
dateIso: "This value should be a valid date (YYYY-MM-DD).",
alphanum: "This value should be alphanumeric.",
phone: "This value should be a valid phone number."
},
notnull: "This value should not be null.",
notblank: "This value should not be blank.",
required: "This value is required.",
regexp: "This value seems to be invalid.",
min: "This value should be greater than or equal to %s.",
max: "This value should be lower than or equal to %s.",
range: "This value should be between %s and %s.",
minlength: "This value is too short. It should have %s characters or more.",
maxlength: "This value is too long. It should have %s characters or less.",
rangelength: "This value length is invalid. It should be between %s and %s characters long.",
mincheck: "You must select at least %s choices.",
maxcheck: "You must select %s choices or less.",
rangecheck: "You must select between %s and %s choices.",
equalto: "This value should be the same."
// parsley.extend ///////////////////////////////,
minwords: "This value should have %s words at least.",
maxwords: "This value should have %s words maximum.",
rangewords: "This value should have between %s and %s words.",
greaterthan: "This value should be greater than %s.",
lessthan: "This value should be less than %s.",
beforedate: "This date should be before %s.",
afterdate: "This date should be after %s.",
americandate: "This value should be a valid date (MM/DD/YYYY)."
},
validateIfUnchanged: false,
errors: {
classHandler: function(elem, isRadioOrCheckbox) {
return $(elem).parents('.form-group');
},
container: function(elem, isRadioOrCheckbox) {},
errorsWrapper: '<div class="help-block well well-sm"></div>',
errorElem: '<span></span>'
},
listeners: {
onFieldValidate: function(elem, ParsleyForm) {
return false;
},
onFormValidate: function(isFormValid, event, ParsleyForm) {},
onFieldError: function(elem, constraints, ParsleyField) {},
onFieldSuccess: function(elem, constraints, ParsleyField) {}
}
};
@AysadKozanoglu
Copy link

thanks a lot really. i want to set custom error message for password equalto retype error.

thanks

@AysadKozanoglu
Copy link

if you want custom locate settings see here for example turkish language
https://github.com/guillaumepotier/Parsley.js/blob/master/dist/i18n/tr.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment