thoughtbot / thoughtbot/form_props

Controlled forms and inputs should always have a `value`

Open
#16 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
50
Forks
0
PR merge metrics
No merged PRs in 30d

Description

When using the controlled options

  form_props(controlled: true, model: Post.new) do |f|
    f.text :title
  end

The output does not contain a value

      "inputs": {
        "title": {
          "type": "text",
          "name": "post[title]",
          "id": "post_title"
        },

This poses a problem in react land because if there suddenly is a value, react will say something to the effect of "uncontrolled component suddenly becomes controlled". So if controlled is used anywhere, we should give it a default value of nil or maybe empty "". I'm not sure which one makes the most sense, and would love some opinions.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the controlled form_props example and the f.text path that produces the shown input JSON. Check existing form helper tests or output fixtures for controlled fields, then determine the project's expected default value behavior. Done means controlled inputs consistently include a value without breaking existing output or React integration.

Written by the indexing model from the issue text.

Assessment

Tech stack
json, rails, react, ruby
Domain
backend, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.