Skip to content

added docs for "Vue.use" options #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import VueFormGenerator from "vue-form-generator";

Vue.use(VueFormGenerator);

/* optional custom validators treated as "built-in"
Vue.use(VueFormGenerator, {
validators: objectWithCustomValidatorFunctions
});
*/

export default {
data () {
return {
Expand Down
34 changes: 33 additions & 1 deletion validation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,39 @@ or function names:

## Custom Validators

You can create custom validators, which are just functions that take `value`, `field`, `model` parameters - and return either an array of errors, or an empty array if validation succeeds. [Full details on creating custom validators can be found here](custom-validators.md).
You can create custom validators, which are functions that take `value`, `field`, `model` parameters - and return either an array of errors, or an empty array if validation succeeds. [Full details on creating custom validators can be found here](custom-validators.md).

If your custom validators are attached to a single object, you can pass this object to `Vue.use()` when setting up VFG in your project. This will take each function in the object passed and attach it to the list of built-in validators. This allows you to reference your custom validators as "name strings" (convenient for JSON schemas retrieved remotely).

### Example of Custom Validators being Installed

```js
import VueFormGenerator from "vue-form-generator";
Vue.use(VueFormGenerator, {
validators: {
firstCustomValidator: (value, field, model) => {
return [];
},
secondCustomValidator: (value, field, model) => {
return [];
},
alwaysInvalid: (value, field, model) => {
return ['I am always invalid'];
}
}
});
```

You can then reference these in your field schema by their name:

```
{
type: "input",
inputType: "text",
model: "model",
validator: ["firstCustomValidator", "secondCustomValidator", "alwaysInvalid"]
}
```

## Handling Validation Events

Expand Down