adamwathan / bootforms

Rapid form generation with Bootstrap 3 and Laravel.
MIT License
417 stars 103 forks source link

Array rules vs inputs array #47

Closed hipolitogb closed 9 years ago

hipolitogb commented 9 years ago

Hi Adam, I found an issue when you are working with input arrays. In these cases, the validation rules in laravel should be added with dots. This makes imposible for the builder finding an error with the input name.

BasicFormBuilder.php, line 25:

    if ($this->builder->hasError($name)) {
        $formGroup->helpBlock($this->builder->getError($name));
        $formGroup->addClass('has-error');
    }

If you have rules like this: $rules['stock_attributes.1'] = "required";

hasError will look for errors at stock_attributes[1], not stock_attributes.1.

I made a quick fix: $name = str_replace('[', '.', $name); $name = str_replace(']', '', $name);

    if ($this->builder->hasError($name)) {

Do you find it OK?

Thanks!

adamwathan commented 9 years ago

Hey! Yeah a few people have brought this up. Working towards support in the package that powers this one, I've got a PR open for it here: https://github.com/adamwathan/form/pull/38

Still need tests for more of the array style cases, feel free to open PRs against that branch if you'd like!