Parsley custom error message doesn't work
Asked Answered
T

3

19

I have the following input field:

<input id="name" name="real_name" type="text" placeholder="ie. Your full name or company name" class="form-control input-lg parsley-validated"
   data-required="true" parsley-error-message="Please insert your name" >

However, when I press my submit button, I only get the standard This value is required. message.

Can anyone tell me why?

Teryl answered 27/1, 2014 at 22:15 Comment(2)
Forgive my unfamiliarity with parsley.js, but what is the expected output? Is this happening even if you submit valid input?Houghton
The input should be Please insert your nameTeryl
R
27

Try this attribute instead of parsley-error-message:

data-parsley-required-message="Please insert your name"

It's not a custom error message for custom validator. You need to override the default 'required' error message with your one.

Riot answered 28/1, 2014 at 12:53 Comment(6)
could you look at my Ajax question aswell? #21392478Teryl
is data-parsley-error-message="my message" only for custom validation ? The documentation says: Customize a unique global message for the field. I toought it was working like @MarcRasmussen said. (i have a local and remote validation for VAT validation and the error message is the same)Willowwillowy
@Leto: I tried data-parsley-error-message and it works for all error messages for that field. It just becomes the error message for any error in that field.Shelba
doesn't work for me i using bootstrap 4 and parsley 2.9.1Misgovern
For more recent versions: data-parsley-required-messageForcefeed
I have required and a custom validation for a field but it is taking data-parsley-error-message for both this didn't help meDiversified
Z
61

Try

data-parsley-required-message="Please insert your name"

Zacharyzacherie answered 18/6, 2014 at 23:3 Comment(6)
Or "data-parsley-error-message" for a generalized response.Tungting
Still doesn't work, always "Please fill out this field"Licht
I think they must have changed the property name or something. This one worked for me with version 2.3.3.Mozellemozes
If you're on later versions, this is the ticket.Inmost
Works for version 2.8.1Vintager
Thanks, this is indeed the correct version now. Reference: parsleyjs.org/doc/#ui-for-fieldUnlace
R
27

Try this attribute instead of parsley-error-message:

data-parsley-required-message="Please insert your name"

It's not a custom error message for custom validator. You need to override the default 'required' error message with your one.

Riot answered 28/1, 2014 at 12:53 Comment(6)
could you look at my Ajax question aswell? #21392478Teryl
is data-parsley-error-message="my message" only for custom validation ? The documentation says: Customize a unique global message for the field. I toought it was working like @MarcRasmussen said. (i have a local and remote validation for VAT validation and the error message is the same)Willowwillowy
@Leto: I tried data-parsley-error-message and it works for all error messages for that field. It just becomes the error message for any error in that field.Shelba
doesn't work for me i using bootstrap 4 and parsley 2.9.1Misgovern
For more recent versions: data-parsley-required-messageForcefeed
I have required and a custom validation for a field but it is taking data-parsley-error-message for both this didn't help meDiversified
T
1

For required field validation :

data-parsley-required-message="Please enter name"

For input pattern validation :

data-parsley-pattern-message="Please enter valid name"

In short change third word with your validation type.

Tympan answered 3/11, 2021 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.