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/action.md
+48Lines changed: 48 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,6 +82,8 @@ success: {
82
82
}
83
83
```
84
84
85
+
#### Perform transition
86
+
85
87
We can also perform a transition that only gets triggered on success and also accepts further params:
86
88
87
89
```ruby
@@ -121,6 +123,52 @@ class TestModelsController < ApplicationController
121
123
end
122
124
```
123
125
126
+
#### Perform redirect
127
+
128
+
We can also perform a redirect (full page load) that only gets triggered on success and also accepts further params:
129
+
130
+
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!
131
+
132
+
```ruby
133
+
success: {
134
+
emit:'my_action_success', # doesn't have an effect when using redirect
135
+
redirect: {
136
+
path::action_test_page2_path,
137
+
params: { id:42 }
138
+
}
139
+
}
140
+
```
141
+
142
+
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.
143
+
144
+
```ruby
145
+
success: {
146
+
emit:'my_action_success', # doesn't have an effect when using redirect
147
+
redirect: {
148
+
follow_response:true
149
+
}
150
+
}
151
+
```
152
+
153
+
A controller action that would create a record and then respond with the url the page should redirect to, could look like this:
154
+
155
+
```ruby
156
+
classTestModelsController < ApplicationController
157
+
includeMatestack::Ui::Core::ApplicationHelper
158
+
159
+
defcreate
160
+
@test_model=TestModel.create(test_model_params)
161
+
162
+
render json: {
163
+
redirect_to: test_model_path(@test_model)
164
+
}, status::ok
165
+
end
166
+
end
167
+
```
168
+
169
+
Same applies for the `failure` configuration.
170
+
171
+
124
172
### Failure
125
173
126
174
As counterpart to the success part of the action component, there is also the possibility to define the failure behavior. This is what gets triggered after the response to our action returns a failure code, usually in the range of `400` or `500` HTTP status codes.
Copy file name to clipboardExpand all lines: docs/components/form.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -185,6 +185,53 @@ class TestModelsController < ApplicationController
185
185
end
186
186
```
187
187
188
+
Same applies for the `failure` configuration.
189
+
190
+
#### Perform redirect
191
+
192
+
We can also perform a redirect (full page load) that only gets triggered on success and also accepts further params:
193
+
194
+
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!
195
+
196
+
```ruby
197
+
success: {
198
+
emit:'my_action_success', # doesn't have an effect when using redirect
199
+
redirect: {
200
+
path::action_test_page2_path,
201
+
params: { id:42 }
202
+
}
203
+
}
204
+
```
205
+
206
+
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.
207
+
208
+
```ruby
209
+
success: {
210
+
emit:'my_action_success', # doesn't have an effect when using redirect
211
+
redirect: {
212
+
follow_response:true
213
+
}
214
+
}
215
+
```
216
+
217
+
A controller action that would create a record and then respond with the url the page should redirect to, could look like this:
218
+
219
+
```ruby
220
+
classTestModelsController < ApplicationController
221
+
includeMatestack::Ui::Core::ApplicationHelper
222
+
223
+
defcreate
224
+
@test_model=TestModel.create(test_model_params)
225
+
226
+
render json: {
227
+
redirect_to: test_model_path(@test_model)
228
+
}, status::ok
229
+
end
230
+
end
231
+
```
232
+
233
+
Same applies for the `failure` configuration.
234
+
188
235
#### Reset form
189
236
190
237
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:
0 commit comments