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
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,6 +38,22 @@ data: {
38
38
}
39
39
```
40
40
41
+
### Confirm
42
+
43
+
When specified, a [browser-native confirm dialog](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm) is shown before the action is actually performed. The action only is performed after the user confirms. The action is not performed if the user declines to confirm dialog.
44
+
45
+
```ruby
46
+
confirm: {
47
+
text:"Do you really want to delete this item?"
48
+
}
49
+
```
50
+
51
+
If no `text` is given, the default text "Are you sure?" will be used.
52
+
53
+
```ruby
54
+
confirm:true
55
+
```
56
+
41
57
### Success
42
58
43
59
The success part of the action component gets triggered once the action we wanted to perform returns a success code, usually the `200` HTTP status code.
@@ -62,6 +78,33 @@ success: {
62
78
}
63
79
```
64
80
81
+
When the server redirects to a url, for example after creating a new record, the transition needs to be configured to follow this redirect of the server response.
82
+
83
+
```ruby
84
+
success: {
85
+
emit:'my_action_success',
86
+
transition: {
87
+
follow_response:true
88
+
}
89
+
}
90
+
```
91
+
92
+
A controller action that would create a record and then respond with the url the page should transition to, could look like this:
93
+
94
+
```ruby
95
+
classTestModelsController < ApplicationController
96
+
includeMatestack::Ui::Core::ApplicationHelper
97
+
98
+
defcreate
99
+
@test_model=TestModel.create(test_model_params)
100
+
101
+
render json: {
102
+
transition_to: test_model_path(@test_model)
103
+
}, status::ok
104
+
end
105
+
end
106
+
```
107
+
65
108
### Failure
66
109
67
110
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.
0 commit comments