You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/100-tutorial/04_forms_edit_new_create_update_delete.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,7 +165,7 @@ Within our response method we have at first a transition to the person index pag
165
165
166
166
Let's take a closer look. Like in Rails with `form_for` you can create a form in matestack with `form`. It takes a hash as first argument for configuration. In this case we defined `new_person_form_config` to return the config hash for our form. In the config hash you can set the http request method, a path, success and failure configs and a for key, which will be explained soon. This form gets submitted as a POST request to the `persons_path`.
167
167
168
-
The `for` key let's us define for what this form is. In this case we pass a empty model to the form component, which will therefore submitt the form inputs wrapped by the model name following the Rails behavior and conventions.
168
+
The `for` key let's us define for what this form is. In this case we pass a empty model to the form component, which will therefore submit the form inputs wrapped by the model name following the Rails behavior and conventions.
169
169
170
170
The 'success' key let's us define a behavior when the form was submitted successful, which means the server returned a status code of 2XX. In this case we tell the form that if successful it should follow the transition path we return in our controller action. So a page transition will happen to the detail page of our newly created model. We could also configure a failure behavior by specifying the `failure` key.
Copy file name to clipboardExpand all lines: docs/guides/200-basic_building_blocks/README.md
+43-1Lines changed: 43 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -479,7 +479,49 @@ Read more about the [action component](/docs/api/100-components/action.md).
479
479
480
480
**forms**
481
481
482
-
Read more about the [forms component](/docs/api/100-components/forms.md).
482
+
Like in Rails with `form_for` you can create a form in matestack with `form`. It takes a hash as parameter with which you can configure your form. In the config hash you can set the HTTP request method, a path, success and failure behavior. You also need to specify a model, string or symbol for what the form is for. All form params will then be submitted nested in this namespace, following Rails behavior and conventions.
form_radio key::newsletter, options: { 'Yeah, a newsletter.': 1, 'Oh no. Not again.': 0 }, label:'Name'
492
+
form_checkbox key::conditions, label:"I've read the terms and conditions"
493
+
form_submit do
494
+
button text:'Save'
495
+
end
496
+
end
497
+
end
498
+
499
+
defform_config
500
+
{
501
+
for:User.new
502
+
path: users_path,
503
+
method::post,
504
+
success: {
505
+
transition: {
506
+
follow_redirect:true
507
+
}
508
+
},
509
+
failure: {
510
+
emit:'user_form_failure'
511
+
}
512
+
}
513
+
end
514
+
```
515
+
516
+
Inside a form you can use our form input components `form_input`, `textarea`, `form_select`, `form_radio` and `form_checkbox`. Each input component requires a `:key` which represents the params name as which this inputs value get's submitted. It is also possible to specify `:label` in order to create labels for the input on the fly. Some form components can take additional `:options` as a array or hash, which will render a the passed options. For inputs with possible multiple values, like checkboxes or multisecelects, the selected values are submitted in an array, following again Rails behavior. To learn more about the details of each input component take a look at the [form components api](/docs/api/100-components/form.md)
517
+
518
+
Wrap a button or any markup which should submit the form when clicked in `form_submit`.
519
+
520
+
Each form requires a few keys for configuration: `:for`, `:path`, `:method`. Like said above, `:for` can reference a active record object or a string/symbol which will be used to nest params in it. `:path` specifies the target path, the form is submitted to with the configured request method in `:method`.
521
+
522
+
Forms will be submitted asynchronously and in case of errors dynamically extended to show errors belonging to inputs fields, but it is possible to set custom form behavior in success or failure cases. You could transition to another page, follow the redirect from the server as a transition or normal redirect, or emit events to leverage the above mentioned event hub.
523
+
524
+
To learn more, check out the [complete form documentation](/docs/api/100-components/form.md).
0 commit comments