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

Dynamically changing attribute string #1001

Open
timinigi opened this issue Feb 24, 2024 · 0 comments
Open

Dynamically changing attribute string #1001

timinigi opened this issue Feb 24, 2024 · 0 comments

Comments

@timinigi
Copy link

Subject of the issue

Hello,

I am dealing with an issue, I have a select input (true/false) and base on the boolean value I am changing second input label between 2 strings. For all my inputs I am using that same label as an attribute name to be used in all validation messages mainly because of localization. All my validations are defined as Form Request Validation.

To correctly change the attribute name base on the select input as well I am currently using attributes() method to override the string base on condition request()->select_value == true and it works just fine for laravel serverside validation, but this package is struggling with this issue.

I know that this package is loading the attributes on page load where request()->select_value is always undefined as well as other form data but I have no idea how to dynamically change attributes directly with javascript or maybe use better variable in the current condition inside attributes() method. Any advice or enhancement would be great!

Your environment

  • version of this package: v4.8.1
  • version of Laravel: v10.43.0

Steps to reproduce

  1. Prepare html form with 2 inputs: first select with true/false and second arbitrary.
  2. Create validation class as Form Request Validation with any validation for second input e.g. required rule.
  3. Customize attribute inside attributes() method and apply condition request()->select_value == true to dynamically change attribute string for the second input base on the first input value.
  4. Apply JsValidator.
  5. Leave second input empty and submit the form.
  6. Observe error message when changing the first input.

Expected behaviour

Changing the error message to use correct attribute string.

Actual behaviour

Error message remains the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant