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

Robust way to pass labels to validator #56

Closed
huglester opened this issue Mar 19, 2015 · 7 comments
Closed

Robust way to pass labels to validator #56

huglester opened this issue Mar 19, 2015 · 7 comments

Comments

@huglester
Copy link

Hello,

I am playing now with the lib. so far very good impressions.
But I can't find on how to link validation labels with labels from this package...

so for example I have this:

            $this
                ->add('pkg', 'text', [
                    'label' => trans('setting.package_label')
                ])

On the form, I see correct Label, but when getting validation errors (using formRequests), of course I see invalid labels.. like 'pkg' and not the translated string.

Maybe you can share some ideas on this? :)

Thank you!

@huglester huglester changed the title Robust way to pass titles to validator Robust way to pass labels to validator Mar 19, 2015
@huglester
Copy link
Author

Form requests support the

    public function attributes()
    {
        return [
            'pkg' => trans('setting.pkg_label'),
            'key' => trans('setting.key_label'),
        ];
    }

so I thought, maybe it would be good idea to add ability pass the FormRequestClass, and the system could for example check if there there are attributes, and if so, try to get label from there.

It could also add even more benefits.. for Example we could call rules() method on Request class,
and for example automaticly add <span class=required>*</span> when the rule required exists and so on.

But maybe there are better ways to do that :)

Thanks!

@kristijanhusak
Copy link
Owner

@kristijanhusak
Copy link
Owner

@huglester , is it working for you now?

@huglester
Copy link
Author

This probably would work, but I am searching for a way, where, for example:
we have country_id.
But maybe I would like the label to be "Country"
but in another place, it should be "Issuer country" or something like that.

Think I will need to extend your class. But thanks for helping @kristijanhusak

@kristijanhusak
Copy link
Owner

You can handle that through Validator, with 3rd parameter to the Make method. Check here
http://laravel.com/docs/5.0/validation#custom-error-messages

@huglester
Copy link
Author

But is there any way to integrate validation all together with this package? so basicly I specify label for forms, and it is used in validator?

I have currently done that in my extension, but wanna make sure it does not exist in this package:) thanks

@kristijanhusak
Copy link
Owner

No, there is no validation, and i'm not planning to add it because Laravel 5 have form requests that handle that pretty well. Only errors are shown, but that is pulled from session.

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

2 participants