Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation message for array not working as expected #423

Open
cnakh opened this issue Apr 11, 2021 · 1 comment
Open

Validation message for array not working as expected #423

cnakh opened this issue Apr 11, 2021 · 1 comment
Labels
docs info needed More information needed

Comments

@cnakh
Copy link

cnakh commented Apr 11, 2021

I am writing code to validate array of emails and phone numbers as follow

var rules = {
    'emails[]': 'required_without:phones[]|array',
    'emails[].*': 'required|email',
    'phones[]': 'required_without:emails[]|array',
    'phones[].*': 'required|digits_between:9,10',
};
var messages = {
    'required_without.emails[]': 'Email is required when no any phones is not present',
    'array.emails[]': 'Emails must be an array',
    'required.emails[].*': 'Email is required',
    'email.emails[].*': 'Email must be a valid email address',
    'required_without.phones[]': 'Phone is required when no any emails is not present',
    'array.phones[]': 'Phones must be an array',
    'required.phones[].*': 'Phone is required',
    'digits_between.phones[].*': 'Phone must be between :min and :max digits'
};

When process of validate the result as follow

{
    "emails[].0": ["The emails .0 field is required."],
    "emails[].1": ["The emails .1 field is required."],
    "emails[].2": ["The emails .2 field is required."],
    "emails[].3": ["The emails .3 field is required."]
}

The error message was not override even I set it in messages
'required.emails[].*': 'Email is required'

How can I solve this issue?

@mikeerickson
Copy link
Owner

@cnakh Would you be able to share a bit more code? I can see how you have defined the rules and messages but I am not sure how you are invoking the validator, and seeing how the incoming data appears, I can advise further.

@mikeerickson mikeerickson added docs info needed More information needed labels Apr 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs info needed More information needed
Projects
None yet
Development

No branches or pull requests

2 participants