Forms

In the end, everything is basically just spreadsheets
Includes a Ruby component and corresponding Rails helper
Ruby

Nitro Kit comes with a custom FormBuilder that works just like the one you already know except it has a few extras.

Example

New Post
Tell the world
  • Title can't be blank
Should we tell the world?
<%= form_with model: @post, url: request.path do |f| %>
  <%= f.fieldset(legend: "New Post", description: "Tell the world") do |fs| %>
    <%= fs.group do %>
      <%= f.field :title %>

      <%= f.field :category_id, as: :select, options: Category.pluck(:name, :id) %>

      <%= f.field :body, as: :textarea, rows: 6 %>

      <%= f.field :publish, as: :checkbox, description: "Should we tell the world?" %>

      <%= f.field :kind,
        as: :radio_group,
        options: Post.kinds.map { |k| [k.capitalize, k] },
        value: "article" %>

      <%= f.submit %>
    <% end %>
  <% end %>
<% end %>

Usage

nk_form_with(**attrs, &block) { |form| ... }
PropertyDefaultDescription
**attrsArguments for NitroKit::FormBuilder.new()

Works just like form_with.

nk_form_for(record, **attrs, &block) { |form| ... }
PropertyDefaultDescription
record
**attrsArguments for NitroKit::FormBuilder.new()

Works just like form_for.

form.fieldset(**attrs, &block) { |fieldset| ... }
PropertyDefaultDescription
**attrsArguments for NitroKit::Fieldset.new()
form.field(field_name, **attrs)
PropertyDefaultDescription
field_name Field name
**attrsArguments for NitroKit::Field.new()