Skip to content

Commit d6eceb8

Browse files
committed
Migrate PR #660
1 parent 217188c commit d6eceb8

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

docs/index.md

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,22 @@ To support validation outside of the form, most commonly on the backend, schema
341341
injecting arbitrary validationMessages to any field and setting it's validity.
342342
343343
This is done via an event that starts with `schemaForm.error.` and ends with the key to the field.
344-
It also takes two arguments, the first being the error code, the second being either a
344+
It also takes two mandatory and an optional arguments, the first being the error code, the second being _either_ a
345345
validation message or a boolean that sets validity, specifying a validation message automatically
346-
sets the field to invalid.
346+
sets the field to invalid. The third and last one is optional and it represents the form name. If the form name is not specified then the event is broadcasted for all the schema forms contained in the controller that is broacasting the event. In case there are multiple forms for a specific controller it could be useful to specify the form name in order to let only the interested form capture the error event.
347347
348348
So lets do an example, say you have a form with a text field `name`:
349349
350+
Html
351+
```html
352+
<form
353+
name="myForm"
354+
sf-schema="schema"
355+
sf-form="form"
356+
sf-model="formData"
357+
ng-submit="onSubmit(myForm)">
358+
</form>
359+
```
350360
Schema
351361
```json
352362
{
@@ -370,6 +380,8 @@ optional validation message.
370380
371381
```js
372382
scope.$broadcast('schemaForm.error.name','usernameAlreadyTaken','The username is already taken');
383+
// or with the optional form name
384+
scope.$broadcast('schemaForm.error.name','usernameAlreadyTaken','The username is already taken', 'myForm');
373385
```
374386
This will invalidate the field and therefore the form and show the error message where it normally
375387
pops up, under the field for instance.
@@ -380,6 +392,8 @@ i.e. `true`.
380392
381393
```js
382394
scope.$broadcast('schemaForm.error.name','usernameAlreadyTaken',true);
395+
// or with the optional form name
396+
scope.$broadcast('schemaForm.error.name','usernameAlreadyTaken',true, 'myForm');
383397
```
384398
385399
You can also pre-populate the validation messages if you don't want to send them in the event.
@@ -1088,13 +1102,13 @@ function FormCtrl($scope) {
10881102
key: "choice",
10891103
type: "radiobuttons",
10901104
style: {
1091-
selected: "btn-success",
1092-
unselected: "btn-default"
1105+
selected: "btn-success",
1106+
unselected: "btn-default"
10931107
},
10941108
titleMap: [
1095-
{ value: "one", name: "One" },
1096-
{ value, "two", name: "More..." }
1097-
]
1109+
{ value: "one", name: "One" },
1110+
{ value, "two", name: "More..." }
1111+
]
10981112
];
10991113
}
11001114
```
@@ -1327,8 +1341,8 @@ function FormCtrl($scope) {
13271341
key: "subforms",
13281342
add: "Add person",
13291343
style: {
1330-
add: "btn-success"
1331-
},
1344+
add: "btn-success"
1345+
},
13321346
items: [
13331347
"subforms[].nick",
13341348
"subforms[].name",
@@ -1349,8 +1363,8 @@ function FormCtrl($scope) {
13491363
add: null,
13501364
remove: null,
13511365
style: {
1352-
add: "btn-success"
1353-
},
1366+
add: "btn-success"
1367+
},
13541368
items: [
13551369
"subforms[].nick",
13561370
"subforms[].name",
@@ -1467,13 +1481,13 @@ function FormCtrl($scope) {
14671481
key: "subforms",
14681482
remove: "Delete",
14691483
style: {
1470-
remove: "btn-danger"
1471-
},
1472-
add: "Add person",
1484+
remove: "btn-danger"
1485+
},
1486+
add: "Add person",
14731487
items: [
14741488
"subforms[].nick",
14751489
"subforms[].name",
1476-
"subforms[].emails",
1490+
"subforms[].emails"
14771491
]
14781492
}
14791493
];

0 commit comments

Comments
 (0)