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
+29-15Lines changed: 29 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -341,12 +341,22 @@ To support validation outside of the form, most commonly on the backend, schema
341
341
injecting arbitrary validationMessages to any field and setting it's validity.
342
342
343
343
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
345
345
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.
347
347
348
348
So lets do an example, say you have a form with a text field `name`:
349
349
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
+
```
350
360
Schema
351
361
```json
352
362
{
@@ -370,6 +380,8 @@ optional validation message.
370
380
371
381
```js
372
382
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');
373
385
```
374
386
This will invalidate the field and therefore the form and show the error message where it normally
0 commit comments