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
There is one section of documentation covering [defaults and form types](docs/index.md). There is another section for how you [extend angular schema form with your own types](https://github.com/Textalk/angular-schema-form/blob/master/docs/extending.md).
44
+
You can find [all documentation here](docs/index.md), it covers all the different field types
45
+
and their options.
46
+
47
+
It also covers how to [extend angular schema form with your own field types](https://github.com/Textalk/angular-schema-form/blob/master/docs/extending.md).
1.[Form defaults in schema](#form-defaults-in-schema)
10
15
1.[Form types](#form-types)
11
16
1.[Default form types](#default-form-types)
@@ -306,6 +311,153 @@ var form = [
306
311
```
307
312
308
313
314
+
Custom Validations
315
+
------------------
316
+
Sometimes the validation you want is tricky to express in a JSON Schema
317
+
or Schema Form does not support it (yet), like `anyOf` and `oneOf`.
318
+
319
+
Other times you really need to ask the backend, maybe to check that the a username is not already
320
+
taken or some other constraint that only the backend can know about.
321
+
322
+
### Inject errors into form aka backend validation
323
+
To support validation outside of the form, most commonly on the backend, schema form lets you
324
+
injecting arbitrary validationMessages to any field and setting it's validity.
325
+
326
+
This is done via an event that starts with `schemaForm.error.` and ends with the key to the field.
327
+
It also takes two arguments, the first being the error code, the second being either a
328
+
validation message or a boolean that sets validity, specifying a validation message automatically
329
+
sets the field to invalid.
330
+
331
+
So lets do an example, say you have a form with a text field `name`:
332
+
333
+
Schema
334
+
```json
335
+
{
336
+
"type":"object",
337
+
"properties": {
338
+
"name": { "type":"string" }
339
+
}
340
+
}
341
+
```
342
+
343
+
Form
344
+
```json
345
+
[
346
+
"name"
347
+
]
348
+
```
349
+
350
+
To inject an error message and set that forms validity via [ngModelController.$setValidity](https://docs.angularjs.org/api/ng/type/ngModel.NgModelController)
351
+
broadcast an event with the name `schemaForm.error.name` with name/code for the error and an
352
+
optional validation message.
353
+
354
+
```js
355
+
scope.$broadcast('schemaForm.error.name','usernameAlreadyTaken','The username is already taken');
356
+
```
357
+
This will invalidate the field and therefore the form and show the error message where it normally
358
+
pops up, under the field for instance.
359
+
360
+
There is a catch though, schema form can't now when this field is valid s you have to tell it by
361
+
sending an event again, this time switch out the validation message for validity of the field,
0 commit comments