Skip to content

Commit 38a7dfb

Browse files
committed
Merge pull request #660 from LeonardoGentile/development
Docs for #656
2 parents a4d80eb + 5a08f68 commit 38a7dfb

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

docs/index.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,23 @@ To support validation outside of the form, most commonly on the backend, schema
347347
injecting arbitrary validationMessages to any field and setting it's validity.
348348
349349
This is done via an event that starts with `schemaForm.error.` and ends with the key to the field.
350-
It also takes two arguments, the first being the error code, the second being either a
350+
It also takes two mandatory and an optional arguments, the first being the error code, the second being _either_ a
351351
validation message or a boolean that sets validity, specifying a validation message automatically
352-
sets the field to invalid.
352+
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.
353353
354354
So lets do an example, say you have a form with a text field `name`:
355355
356+
Html
357+
```html
358+
<form
359+
name="myForm"
360+
sf-schema="schema"
361+
sf-form="form"
362+
sf-model="formData"
363+
ng-submit="onSubmit(myForm)">
364+
</form>
365+
```
366+
356367
Schema
357368
```json
358369
{
@@ -376,6 +387,8 @@ optional validation message.
376387
377388
```js
378389
scope.$broadcast('schemaForm.error.name','usernameAlreadyTaken','The username is already taken');
390+
// or with the optional form name
391+
scope.$broadcast('schemaForm.error.name','usernameAlreadyTaken','The username is already taken', 'myForm');
379392
```
380393
This will invalidate the field and therefore the form and show the error message where it normally
381394
pops up, under the field for instance.
@@ -386,6 +399,8 @@ i.e. `true`.
386399
387400
```js
388401
scope.$broadcast('schemaForm.error.name','usernameAlreadyTaken',true);
402+
// or with the optional form name
403+
scope.$broadcast('schemaForm.error.name','usernameAlreadyTaken',true, 'myForm');
389404
```
390405
391406
You can also pre-populate the validation messages if you don't want to send them in the event.
@@ -1094,10 +1109,10 @@ function FormCtrl($scope) {
10941109
key: "choice",
10951110
type: "radiobuttons",
10961111
style: {
1097-
selected: "btn-success",
1098-
unselected: "btn-default"
1099-
},
1100-
titleMap: [
1112+
selected: "btn-success",
1113+
unselected: "btn-default"
1114+
},
1115+
titleMap: [
11011116
{ value: "one", name: "One" },
11021117
{ value, "two", name: "More..." }
11031118
]
@@ -1333,8 +1348,8 @@ function FormCtrl($scope) {
13331348
key: "subforms",
13341349
add: "Add person",
13351350
style: {
1336-
add: "btn-success"
1337-
},
1351+
add: "btn-success"
1352+
},
13381353
items: [
13391354
"subforms[].nick",
13401355
"subforms[].name",
@@ -1355,8 +1370,8 @@ function FormCtrl($scope) {
13551370
add: null,
13561371
remove: null,
13571372
style: {
1358-
add: "btn-success"
1359-
},
1373+
add: "btn-success"
1374+
},
13601375
items: [
13611376
"subforms[].nick",
13621377
"subforms[].name",
@@ -1473,9 +1488,9 @@ function FormCtrl($scope) {
14731488
key: "subforms",
14741489
remove: "Delete",
14751490
style: {
1476-
remove: "btn-danger"
1477-
},
1478-
add: "Add person",
1491+
remove: "btn-danger"
1492+
},
1493+
add: "Add person",
14791494
items: [
14801495
"subforms[].nick",
14811496
"subforms[].name",

0 commit comments

Comments
 (0)