-
Notifications
You must be signed in to change notification settings - Fork 9
Customizing Forms
You can generate the form partials to edit shown fields or the whole form with the following generator :
rails g para:form <your_model_name>
If you need to separate your form in multiple field sets, you can use Para's #fieldset
form helper.
It is used by default in all generated forms, but you can add multiple fieldsets, and give them a title with the :title
option.
= para_form_for(resource) do |form|
= form.fieldset title: 'Informations' do
= form.input :name
= form.fielset title: 'Price' do
= form.input :price
= form.actions
Para's form builder comes with a builtin tabs helper that allows you to build a simple tabbed navigation in your form.
In the following example, we'll imagine an Order
model's form with tabs allowing to separate the different components of the order :
= para_form_for(resource) do |form|
= form.tabs do |tabs|
= tabs.tab :totals, icon: 'shopping-cart' do
= form.input :total_eot_price
= form.input :total_price
= tabs.tab :customer, icon: 'user' do
= form.input :customer
= form.input :billing_address
= form.input :shipping_address
= tabs.tab :line_items, icon: 'list' do
= form.input :line_items, as: :nested_many
Now to customize your tab's title, you just need to override the forms.tabs.<your_model>.<tab_identifier>
. For the first tab, we'll fill the following key : forms.tabs.order.totals
.
Alternatively, you can use the tabs title directly in the tab name :
= tabs.tab "Order totals", icon: 'shopping-cart' do
would also work.
Note that the :icon
option of the tabs.tab
helper is optional.