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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Set validation attributes on the fly #655

Closed
PhiloNL opened this issue Mar 22, 2013 · 4 comments

Comments

Projects
None yet
4 participants
@PhiloNL
Copy link
Contributor

commented Mar 22, 2013

This is a proposal based on issue #439.

Would love to see this 馃憤
Because using the custom attributes in the language file requires you to do multiple translations for the same field and it's not very dynamic.

<label>{{ trans('site.email') }}}</label> // Translates to Email address
{{ Form::input('text', 'email') }}
{{ $errors->first('email') }} // The email field is required.

If I would want to change the :attribute to the 'site.email' translation I would also need to add "Email address" to the validation.php language file. While it would be more dynamic if I could set this as an extra parameter:

$attributes = array('email' => trans('site.email'));
$validation = Validator::make($input, $rules, array(), $attributes);

Also when working with dynamically generated forms this would be very useful.
Dynamically generated input fields often have names that refer to the id of the field for example:

{{ Form::input('text', 'field[' . $field->id . ']') }}
{{ $errors->first('field[' . $field->id . ']') }} // The 347 field is required.

We can easily fix this by generating an attributes array and passing it to the validator.

$attributes = array();

foreach($fields as $field){
   $attributes[$field->id] = $field->name;
}

$validation = Validator::make($input, $rules, array(), $attributes);

I've got this working, and would like to make a proposal to add this feature :)
https://github.com/Philo01/framework/compare/feature;validation-attributes-on-the-fly

@vfragosop

This comment has been minimized.

Copy link

commented Mar 22, 2013

馃憤 I would kill for that on our L3 app.

@taylorotwell

This comment has been minimized.

Copy link
Member

commented Mar 23, 2013

Done. Fixes #439

@taylorotwell

This comment has been minimized.

Copy link
Member

commented Mar 23, 2013

You may call setAttributeNames on a Validator instance now.

@pilot911

This comment has been minimized.

Copy link
Contributor

commented Dec 5, 2013

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.