rbui-labs / rbui

Ruby gem for RBUI Components
https://rbui.dev/
MIT License
190 stars 22 forks source link

Form component needs more extensive documentation #134

Open oskargargas opened 1 week ago

oskargargas commented 1 week ago

I'm using v1 branch and reading docs at https://rbui.dev/docs/form

Form component is very lightly documented. Documentation shows how to visually build the form but misses the most important stuff - interaction. By looking through code I was able to find way to pass action, HTTP method nad input names but this stuff should be documented for ease of use.

In best case scenario I'd see docs expanded by at least 2 examples.

  1. Simple, 1 field form, complete with action names, etc.
  2. Complex real world example, ex. Devise login form
cirdes commented 1 week ago

@oskargargas, you make a valid point. It would be nice to document forms a bit more thoroughly.

Right now, I'm using forms with form_with helpers, but we have to define the input names ourselves.

form_with(url: buyer_setting_groupers_path(@setting_grouper.buyer)) do
  FormField(class: "flex-1") do
    FormFieldLabel(for: "setting_grouper[display_name]") { "New group" }

    div(class: "flex flex-row items-center justify-between gap-4") do
      Input(
        required: true,
        id: "setting_grouper[display_name]",
        name: "setting_grouper[display_name]",
        placeholder: "Fill here."
      )
    end

    FormFieldError { @setting_grouper.errors.full_messages_for(:display_name).first }
  end

  Button(size: :sm, type: "submit") { "Create" })
end

I have opened this PR on Rails to try to access the input attributes to make integration with Rails even easier, but it hasn't been merged yet.