adamwathan / form

Super basic form HTML builder, only really exists so I can pull it in for some other more useful projects.
MIT License
232 stars 117 forks source link

Old input binding fix for checkbox & radio when chaining value() #71

Closed jesseleite closed 8 years ago

jesseleite commented 8 years ago

Old input binding doesn't work on checkbox & radio when chaining ->value().

$form->radio('my_field')->value($value)

But it does work when passing value into element constructor:

$form->radio('my_field', $value)

I narrowed down to this code. Since old input binding on checkbox and radio elements require checking against the element's value, we can't perform this logic in the constructor because it ignores the fact that the user could have set the value later with value(). My proposed fix saves old input onto the element as private property, so that the binding logic can be performed later.

I feel like it's kind of dirty saving old input on the element as a property, but I couldn't find a way to access the parent form object from within the element object. Open to your thoughts.

jesseleite commented 8 years ago

Ready for review :8ball: