Skip to content

Commit bbbc9ad

Browse files
committed
Add errors to change event
1 parent 21cec95 commit bbbc9ad

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "json-form-custom-element",
33
"private": false,
4-
"version": "1.4.5",
4+
"version": "1.5.1",
55
"description": "JSON Schema based form generator",
66
"main": "build/custom-element.js",
77
"repository": "git://github.com/json-tools/json-form.git",

src/CustomElement.elm

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ initForm schema value config =
6262
|> Maybe.withDefault Encode.null
6363
)
6464
, ( "isValid", form.errors |> Dict.isEmpty |> Encode.bool )
65+
, ( "errors", form.errors |> Encode.dict (String.join "/") (Encode.list Encode.string) )
6566
]
6667
|> Encode.object
6768
|> valueUpdated
@@ -118,15 +119,16 @@ update message model =
118119

119120
( value, exCmd ) =
120121
case exMsg of
121-
Json.Form.UpdateValue v isValid ->
122+
Json.Form.UpdateValue v errors ->
122123
( v
123124
, Encode.object
124125
[ ( "value"
125126
, v
126127
|> Maybe.withDefault JsonValue.NullValue
127128
|> JsonValue.encode
128129
)
129-
, ( "isValid", Encode.bool isValid )
130+
, ( "isValid", errors |> Dict.isEmpty |> Encode.bool )
131+
, ( "errors", errors |> Encode.dict (String.join "/") (Encode.list Encode.string) )
130132
]
131133
|> valueUpdated
132134
)

src/custom-element.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ customElements.define('json-form',
5252
});
5353
this.app = app;
5454

55-
app.ports.valueUpdated.subscribe(({ value, isValid }) => {
56-
const event = new CustomEvent('change', { detail: { value, isValid } });
55+
app.ports.valueUpdated.subscribe(({ value, isValid, errors }) => {
56+
const event = new CustomEvent('change', { detail: { value, isValid, errors } });
5757
this._muteAttributeChange = true;
5858
this.setAttribute('value', JSON.stringify(value));
5959
this.dispatchEvent(event);

0 commit comments

Comments
 (0)