auraphp / Aura.Input

Tools to describe HTML form fields and values.
MIT License
65 stars 11 forks source link

Add support for adding messages in closure rules #40

Closed kenjis closed 9 years ago

kenjis commented 10 years ago

This PR makes it possible to add messages in a closure.

        $filter->setRule(
            'foo',
            'Enter Foo correctly',
            function ($value) use ($filter) {
                $pass = true;
                if ($value == '') {
                    $filter->addMessages('foo', 'Foo is required');
                    $pass = false;
                }

                if (! ctype_alpha($value)) {
                    $filter->addMessages('foo', 'Foo should be alpha only');
                    $pass = false;
                }
                return $pass;
            }
        );
harikt commented 10 years ago

Thanks. I had a look into it.

I will leave this to @pmjones to decide :+1: .

Thank you for all the Japanese articles you have been pushing.

stephen-hill commented 9 years ago

I too would like to see this merged please :+1:

pmjones commented 9 years ago

Thanks @kenjis -- multiple rules is something I'd like to avoid, but multiple messages seems OK.

kenjis commented 9 years ago

Thanks for your merging!

koriym commented 9 years ago

@kenjis nice ! :+1: