I wanted to customized the error message for email validation when it fails the constraint:
email(size: 1..255, blank: false, email:true)
this displays message like this:
Property [email] of class [class
com.companyname.icmgrails.nonpersistentdomains.UserProfile] with value
[eulinda] is not a valid e-mail address
I could not figure out how to use that and put it in my messages.properties like the example below when email is blank.
com.companyname.icmgrails.nonpersistentdomains.UserProfile.email.blank=Email
should not be blank!
tried solutions:
I used
[com.companyname.icmgrails.nonpersistentdomains.UserProfile.email]
+ notavalidemail or notvalid or notavalidemaladdress or notvalidemaladdress
but was unsucessfull. ANyone can tell me how to use it? thanks
Every constraint specifies the required message code on its reference page in the user guide. In the case of the email constraint you need
com.companyname.icmgrails.nonpersistentdomains.UserProfile.email.email.invalid=Not a valid email address
Related
Kind of new to data annotations for validation and need some help on a weird issue I am having. This is a Blazor server application but not sure that makes any difference. In my model I have many properties but this is where the issue is:
[Url]
public string WebsiteURL { get; set; }
As you can see I do not have the [Required] attribute set as I just want to validate if there is text in the textbox. It displays the error message as I would expect when a bad URL is entered:
Now, if I clear the textbox, the error still remains:
I want the validation error message to clear if the textbox is cleared after the validation message is displayed. Even if I click my submit button, the message is still there. How can I do this?
Thank you,
Jim
It seems with is an issue with a few of the data annotation validator tags:
https://github.com/dotnet/runtime/issues/53820
It is strange to me because if I want the value to NOT be blank or null then [Required] should be used for this. I understand the [Url] tag checks for correct format, but it should allow or have an option tag to allow blanks/nulls as well.
To get around this, I had to use RegEx validators for Urls and Email addresses.
Thanks all,
Jim
We're trying to pre-fill the email address field of a hosted MailChimp form. Here's the blog post that talks about exactly this matter: https://blog.mailchimp.com/how-to-pre-fill-items-on-your-mailchimp-hosted-form/.
So here's our Newsletter signup form without any validation errors:
https://camping.us2.list-manage.com/subscribe/post?u=761a52bbd46ab21474b3af314&id=5cc638b5e6.
The problem arises when I add an email address to the URL as the value for the first form field, MERGE0, like this (url-encoding the email address, so # becomes %40):
https://camping.us2.list-manage.com/subscribe/post?u=761a52bbd46ab21474b3af314&id=5cc638b5e6&MERGE0=test%40camping.info.
Now, the form correctly copies the email address into the input field with name MERGE0 but it also displays three validation error messages:
Note: the email address field is mandatory.
When I try to pre-fill the user's first or last name fields adding MERGE1=John or MERGE2=Doe to the form's url, all is well - no error happens. It seems to be a problem with mandatory fields.
I'm arguing that this is a problem on MailChimp's side but they refuse to help saying that this is custom code and none of their business.
Can anybody help fix these errors?
It turned out that the problem was caused by a mistake in the URL.
Instead of camping.us2.list-manage.com/subscribe/POST?u=761a52bbd46ab...
it had to be camping.us2.list-manage.com/subscribe?u=761a52bbd46ab...
And the errors were gone!
This really made sense in the end, because posting the form should actually trigger the validation.
I am working on IBM Integration toolkit. I wanted to understand the exact validation feature of a particular input node via an example. Can anyone help?
Validation on inputs node you can see them in validation tab, you can choose how to validate (content, conent and value or none if you like to implement your own vaildation and what to do if this validate is failure (Exception , Exception List , user trace, log local error),
validation done automatically depends on the message parser : [BLOB, XMLNSC, XMLNS, SOAP, MRM, ..etc ], and message structurewhich is defined in your message set.
for example :
If you create a message set with message definition file and this message definition has got and element and this element is required and integer, and you set this message set to your input node, validation feature runs automatically if you put for example string value or you left it empty validation exception occurs.
I have a group domain object with 3 fields - username, password and email address
Prior to saving the object, I obfuscate the email address so its not stored in plaintext in our database as its a business requirement
I noticed some strange behaviour when I call validate on the domain object.
The constraints for the fields are as follows
userName (nullable: false, unique: false,blank: false, size: 4..200,widget: "textField", matches: "[a-zA-Z0-9, .-##~{}!£%&*^()-_]+")
password (nullable: false, unique: false,blank: false, size: 4..200,widget: "textField", password: true, matches: "[a-zA-Z0-9, .-##~{}!£%&*^()-_]+")
emailAddress (nullable: false, unique: false,blank: false, size: 5..200,widget: "textField",email: true, matches: "[a-zA-Z0-9, .-##~{}!£%&*^()-_]+")
For the object, I validate it to ensure all the values are as expected (emailAddress not obfuscated yet)
If valid I obfuscate the email address and then call save with the value of validate: false
The strange behaviour is as follows
If I fill in a valid email Address and a valid password - the object fails validation on the userName field as it cannot be blank
If I fill in a valid email Address and a valid username- the object fails validation on the password field as it cannot be blank and also on the email Address and it shows the obfuscated value of the email address in the message
I thought first that the obfuscation was causing the problem but it works fine in the case of the password field being entered
Its the exact same code flow for both scenarios.
Is it possible that grails is calling the validate method for the scenario where the password field is not filled in after I obfuscate the email address?
The code flow is as follows
def userLoginUserInstance = UserLoginUser.get(params.id)
userLoginUserInstance.properties = params
if (userLoginUserInstance.validate()) {
//perform updates to database by obfuscating email address first - working fine
} else {
def newObfuscatedEmailAddress = userLoginUserInstance.emailAddress.encodeAsBase64();
userLoginUserInstance.setEmailAddress(newObfuscatedEmailAddress);
render(view: "edit", model: [userLoginUserInstance: userLoginUserInstance])
}
The reason the email address is obfuscated when validation fails is that the gsp reads a transient variable which has a getter than deObfuscates the email address. When the above code runs where a username is not set, it works fine and the email address shows as being ok.
If the password is blank, the error for the password shows but also the obfuscated email address shows as being invalid.
On Further analysis, the validation problem is happening when I run the following line of code
userLoginUserInstance.setEmailAddress(newObfuscatedEmailAddress);
I understand why this is happening as userLoginUserInstance is retrieved from the database.
What confuses me is that this doesnt happen in all scenarios
The validation error is happening because you are trying to store a Base64 String into an attribute which has an email-constraint:
"foo#bar.com".encodeAsBase64()
results in
Zm9vQGJhci5jb20=
So now when your User entity is flushed to the database again of course another validation is happening, complaining that this is no valid email address.
The reason, why the validation errors are not raised in all scenarios may be, that you do not enforce a user.save() nor user.save(flush:true).
This means the email address is not updated ad-hock, but some time later. To see better what's going on add another validation block after the email is assigned.
Sorry for not getting back to this sooner
I solved this by passing a new object back to the view and not the object from the database
Because I have a requirement to obfuscate the email address it really overly complicated this use case
Thanks for your help with this one guys
Regards
Damien
I'm having problems trying to make angular run all the validations of an input at once.
Here is a jsfiddle example of my problem http://jsfiddle.net/carpasse/GDDE2/
if you type 1 character on the email input you get this "The minimum lenght is 3." error message
and is not until you type 2 more characters than you get the other error message "This is not a valid email."
Does anybody know how to make angular show both error messages at the same time??
Thanks a lot in advance
You problem is not that all the validators are not being run - they are!
Remember that the way these validations work is by passing the view values through a pipeline of transformation functions, which can also specify the validity of the value.
The problem is that the min length validator passes undefined down the pipeline if it is not valid and that the email validator says that undefined is a valid email address!
Try creating your own validation directive that says that undefined is not a valid email address and you will find both errors are showing: http://jsfiddle.net/eKfj3/