formers / former

A powerful form builder, for Laravel and other frameworks (stand-alone too)
https://formers.github.io/former/
1.34k stars 204 forks source link

Add a Choice field type #573

Closed dariusj18 closed 4 years ago

dariusj18 commented 6 years ago

I have been working on an extra feature to make for a different style select/checkbox/radio option similar to some other form libraries.

By having a Choice field type it makes selects, checkboxes, and radios use the same methods and allow for render time decisions. Using the methods multiple() and expanded() tells the control which element it will render.

This also solves some of the confusion of how checkbox/radio is used for single and/or multiples.

If you could look at my branch so far and advise. I also had to make a change to when$framework->getFieldClasses is called since the classes would not be solidified until render time.

https://github.com/dariusj18/former/tree/choice

claar commented 6 years ago

Nice! I've made a couple of comments in your repo.

In general, it looks like really amazing work. Thank you!

If it weren't for the backwards-compatibility question, I'd be tempted to merge this in immediately. I'll let you respond either here or on your repo about the span1_text() backwards compatibility issue before we decide how to land this.

dariusj18 commented 6 years ago

span_text() should still work, it's just that it adds the classes on render instead of on instantiation. It holds the extra modifiers in the field and uses them with the $framework->getFieldClasses() the same as before. The unit test didn't run a render, so the class didn't get applied yet, that is why I changed the test. (This is still a slight backwards compatibility issue, though not so great as to remove the usage of span1_text())

https://github.com/dariusj18/former/commit/f19b993145ca7a10ed87896fe7f89a539667fe58#diff-f766cb0467e9314d9016abac932e69e5

https://github.com/dariusj18/former/commit/f19b993145ca7a10ed87896fe7f89a539667fe58#diff-adc6628c528b64881525b1ce7e00f73e

I also still need to write the tests for checkboxes and radios.

claar commented 6 years ago

Ah, my mistake. I don't think pre-render changes are a significant backwards-compatibility issue, so that's no big deal in my mind.

Love the direction you're going with this -- thanks again.

dariusj18 commented 4 years ago

Done, merged in #574