Parsely.js override default validation messages - javascript

Does anyone here know how you can override validation messages during setup.
I would like to be able to during setup $('form').parsley() to change/define validation messages messages for lets say:
data-parsley-required-message ="some relevant custom message"
I want this to be assigned to all validations so if the field is set to required it will display the custom message as default.
Thanks in advance 8-)

Look in the documentation for window.ParsleyUI.updateError(parsleyInstance, name, message);.
This is assuming version 2, if you are still on 1.X let me know and I will amend the answer.

Related

Bypass parsley.js localization catalog and use gettext() in js

I'm using parsley.js for client-side validation - so far so good!
I'm using transifex to store messages for localization. I would like to find a way to use something like gettext() in the javascript for message translation instead of the parsley catalogs. What is the correct way to do this? I've tried updating the english (default) messages and it doesn't seem to work. I'm new to Parsleyjs so forgive me if I'm asking an obvious question but I can't figure it out.
This is not working (from parsley.js):
Parsley.addMessages('en', {
defaultMessage: gettext('This field seems to be invalid.'),
...
You could override window.Parsley.getErrorMessage to suit your needs.

semantic ui remote validation

I am using Semantic UI along with ASP.NET MVC. I have performed client-side validation in my registration form as described in the documentation http://semantic-ui.com/modules/form.html Now i want to validate an email in order to be unique. So i have to make an ajax request to the server (this is something i know how to do). But how can i add such a rule in Semantic UI and display a corresponding error message?
After a little search at the docs I found the behavior add errors. It works like
$('.your.ui.form').form('add errors', ['Your error string 1', 'Maybe another one?']);
However, this will only change the text in the error messages. If the error message is not displayed at that time, you will probably want to show it. Add the class 'error' to the form:
$('.your.ui.form').addClass('error');
And of course you can chain these two methods like
$('.ui.form')
.form('add errors', ['oh my error'])
.addClass('error');
Here's a fiddle

testing angularjs application using casperjs

When testing an Angular application using Casper I found that the binding between inputs and model didn’t seem to be happening when I filled in form fields. I used Casper’s fill method but found that the Angular form validation was rejecting any required fields as though they were still blank.
Name
Email
Subject
Message
I'm looking around to do something similar, but slightly different (my problem as yet unsolved). However while looking I came across the following article that would appear to be what you want.
http://blog.freeside.co/post/41774715101/testing-angular-forms-with-casper
Basically the fill method in casper doesn't trigger Angular's input event, so Angular doesn't do its thing and you end up with blank post data. The blog entry shows how to override the fill method with coffeescript so the event gets fired.
Hope this helps.

MVCControlsToolkit and Validation

Today I installed the MVC3ControlsToolkit from NuGet, and proceeded to add a a DateTimeFor control to a Scaffolding generated page. I only changed one line of code, but the page was no longer visible, and an exception was thrown, saying validation was happening twice.
If I set UnobtrusiveJavaScriptEnabled to false in my Web.config, I can view the page. Funny thing is that if I restore the page to it's previous state (ie. default config) the error persists.
The error I get is: "Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required"
If anyone can shed some light on this, I'd really appreciate it.

jQuery plugin: Validation can't be customized without setting all fields to 'required'?

I've spent the day looking at jQuery plugin: Validation by Jörn Zaefferer. I notice that it works fine as long as you call the validate() method without options. In my little squalid world, as soon as I add options, like errorPlacement, I notice that validation ignores form fields that are not marked required. I also notice that many, many demos mark all fields required---or do not pass options. Am I writing about anything familiar here? Or should I astral project to a parallel universe?
Note: This is to close the question out and provide info to resolve this to the next person finding the question since the OP has resolve the issue.
If there are any errors in the options, it will act the same as ignoring the fields, this isn't the validation plugin behavior per se, but rather how javascript works overall...any errors and it blows up (in mosts cases).
Double check all your options and use either Chrome's tools or FireBug to see if there are any script errors at all. Judging from your question, this seems the most likely culprit, fixing any errors in your options/errorPlacement will eliminate the onstacle in making the validation plugin work.
Also for testing, it's very helpful to use the debug option on the validation plugin, like this:
$("form").validate({
//other options
debug: true
});
This prevents the form from actually submitting, allowing you to tweak the validation much faster.

Categories