feat(builder): hidden_field alias for Rails FormBuilder migration - #21
Merged
Conversation
## Summary `form.hidden_field(:accepted_terms_document_id, value: x)` raised NoMethodError because Forms::Form has no snake_case Rails FormBuilder API — only the PascalCase `Hidden` escape hatch. Add `hidden_field` to PhlexForms::Builder as a snake_case alias delegating to the same model-bound `Field#hidden` path, so Rails hosts can migrate hidden-field call sites verbatim. An explicit `value:` still wins over the model's current value. Lives on the Builder mixin, so both Forms::Form and FieldsForBuilder (nested fields_for) get it. ## Test Coverage - renders a scoped hidden input honoring an explicit value: override - binds value from the model when none is passed - renders under the plain theme too (bare hidden input) ## Verification - [x] bundle exec rubocop lib spec passes - [x] bundle exec rspec passes (165 passed, 1 pending)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
form.hidden_field(:accepted_terms_document_id, value: TermsDocument.current&.id)raised:Forms::Formexposes the PascalCase escape hatchf.Hidden(:name)but no snake_case RailsFormBuilderAPI, so straighthidden_fieldmigrations from ActionView hit aNoMethodError.This adds
hidden_fieldtoPhlexForms::Builderas a snake_case alias that delegates to the same model-boundField#hiddenpath asHidden. An explicitvalue:still wins over the model's current value (kwargs merge order inField#hidden), sof.hidden_field(:token, value: x)ports over verbatim. Because it lives on the sharedBuildermixin, bothForms::FormandFieldsForBuilder(nestedfields_for) get it.Test Coverage
hidden_fieldrenders a scoped hidden input honoring an explicitvalue:override (name="user[accepted_terms_document_id]",value="42")value="abc123")<input type="hidden">) — theme parityVerification
bundle exec rubocop lib spec— cleanbundle exec rspec— 165 passed, 1 pendingDeviations & judgment calls
Field#hiddenalready readsvalue: field_valuefrom the model and lets a callervalue:in the splat win.hidden_fielddelegates to it unchanged — no duplicate value-handling.LegacyFormMethodcop unchanged. It still nudgeshidden_field→Hidden. The method now runs (enables migration) while the cop keeps steering hosts toward the idiomatic API over time — a lint nudge and a working method are complementary, not contradictory.hidden_fieldonly — the one reported failure — not the whole Rails*_fieldfamily. The cop'sINPUT_TYPE_METHODS/OTHER_LEGACY_METHODSmaps enumerate the rest; if hosts hit moreNoMethodErrors mid-migration, those are the follow-up list.Buildermixin, not justForms::Form, so nestedfields_forbuilders get it for free — both include the mixin.