Skip to content

Commit 87be344

Browse files
jonasjabarigitbook-bot
authored andcommitted
GitBook: [main] 63 pages modified
1 parent 19b5b8c commit 87be344

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

docs/built-in-reactivity/reactive-forms/form-component-api.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ def form_config
403403
input: { class: 'my-field-error' }
404404
}
405405
}
406+
end
406407
```
407408

408409
Outputs errors as:
@@ -418,6 +419,48 @@ Outputs errors as:
418419
<!-- without any errors, because its config takes precedence over the form config -->
419420
```
420421

422+
#### Error message rendering
423+
424+
Given a server error response like that:
425+
426+
```javascript
427+
{
428+
"errors": {
429+
"title": ["can't be blank"]
430+
},
431+
"message": "Something went wrong"
432+
}
433+
```
434+
435+
now including a `message` which is not mapped to an input field, we can display this error message like:
436+
437+
```ruby
438+
def response
439+
matestack_form form_config do
440+
form_input key: :foo, type: :text
441+
# ...
442+
end
443+
# somewhere else or within the form:
444+
toggle show_on: :form_failed, hide_on: :form_succeeded do
445+
plain "{{event.data.message}}"
446+
end
447+
end
448+
449+
def my_form_config
450+
{
451+
#...
452+
success: {
453+
emit: "form_succeeded"
454+
},
455+
failure: {
456+
emit: "form_failed"
457+
}
458+
}
459+
end
460+
```
461+
462+
The `matestack_form` component emits the event together with all errors and the message coming from the server's response. The `toggle` component can then access all this data via `event.data.xyz`
463+
421464
## Loading state
422465

423466
The form will get a 'loading' css class while submitting the form and waiting for a server response:

docs/custom-reactivity/matestacks-vue.js-apis-wip.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ Vue.component('some-component', {
4646
mounted(){
4747
MatestackUiCore.eventHub.$on("some-event", this.reactToEvent)
4848
},
49-
beforeDestroy: function() {
50-
eventHub.$off("some-event", this.reactToEvent)
49+
beforeDestroy(){
50+
MatestackUiCore.eventHub.$off("some-event", this.reactToEvent)
5151
}
5252
})
5353
```

0 commit comments

Comments
 (0)