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/components/form.md
+48-1Lines changed: 48 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -163,6 +163,53 @@ class TestModelsController < ApplicationController
163
163
end
164
164
```
165
165
166
+
Same applies for the `failure` configuration.
167
+
168
+
#### Perform redirect
169
+
170
+
We can also perform a redirect (full page load) that only gets triggered on success and also accepts further params:
171
+
172
+
Please be aware, that emiting a event doen't have an effect when performing a redirect instead of a transition, as the whole page (including the surrounding app) gets reloaded!
173
+
174
+
```ruby
175
+
success: {
176
+
emit:'my_action_success', # doesn't have an effect when using redirect
177
+
redirect: {
178
+
path::action_test_page2_path,
179
+
params: { id:42 }
180
+
}
181
+
}
182
+
```
183
+
184
+
When the server redirects to a url, for example after creating a new record, the redirect needs to be configured to follow this redirect of the server response.
185
+
186
+
```ruby
187
+
success: {
188
+
emit:'my_action_success', # doesn't have an effect when using redirect
189
+
redirect: {
190
+
follow_response:true
191
+
}
192
+
}
193
+
```
194
+
195
+
A controller action that would create a record and then respond with the url the page should redirect to, could look like this:
196
+
197
+
```ruby
198
+
classTestModelsController < ApplicationController
199
+
includeMatestack::Ui::Core::ApplicationHelper
200
+
201
+
defcreate
202
+
@test_model=TestModel.create(test_model_params)
203
+
204
+
render json: {
205
+
redirect_to: test_model_path(@test_model)
206
+
}, status::ok
207
+
end
208
+
end
209
+
```
210
+
211
+
Same applies for the `failure` configuration.
212
+
166
213
#### Reset form
167
214
168
215
If submitted successfully, the `form` component resets its state by default when using the "post" method. When using the "put" method, the state is not resetted by default. You may control this behavior explictly by using the `reset` option:
@@ -1348,4 +1395,4 @@ datalist id: 'datalist-id' do
0 commit comments