Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controlled forms and inputs should always have a value #16

Open
jho406 opened this issue Jun 7, 2024 · 1 comment
Open

Controlled forms and inputs should always have a value #16

jho406 opened this issue Jun 7, 2024 · 1 comment

Comments

@jho406
Copy link
Contributor

jho406 commented Jun 7, 2024

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.

@jho406 jho406 changed the title Controlled should always have value. Controlled forms and inputs should always have a value Jun 7, 2024
@jho406
Copy link
Contributor Author

jho406 commented Jun 7, 2024

The only wrench to this is, when f.select has multiple: true, the value default (with controlled: true) should be an empty array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant