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/index.md
+28-13Lines changed: 28 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -347,12 +347,23 @@ To support validation outside of the form, most commonly on the backend, schema
347
347
injecting arbitrary validationMessages to any field and setting it's validity.
348
348
349
349
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
351
351
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.
353
353
354
354
So lets do an example, say you have a form with a text field `name`:
355
355
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
+
356
367
Schema
357
368
```json
358
369
{
@@ -376,6 +387,8 @@ optional validation message.
376
387
377
388
```js
378
389
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');
379
392
```
380
393
This will invalidate the field and therefore the form and show the error message where it normally
0 commit comments