Skip to content
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

Add usage with Ant Design Vue #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
69 changes: 69 additions & 0 deletions docs/other_frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,72 @@ Use it like so:
v-model="$v.form.name"
/>
```

## Usage with Ant Design Vue

Ant Design Vue exposes the `a-form-item` component, which has `validate-status` and `help` props. We supply a type of `error` and the `firstErrorMessage` to these respectively.

```vue
<template>
<a-form-item
:validate-status="validateStatus"
:help="firstErrorMessage"
has-feedback
v-bind="$props"
>
<slot
:attrs="{ state: isValid }"
:listeners="{ input: () => preferredValidator.$touch() }"
/>
</a-form-item>
</template>

<script>
import { singleErrorExtractorMixin } from 'vuelidate-error-extractor';

const validationStatus = {
ERROR: 'error',
SUCCESS: 'success',
};

export default {
extends: singleErrorExtractorMixin,
computed: {
validateStatus() {
if (this.hasErrors) {
return validationStatus.ERROR;
}

if (this.isValid) {
return validationStatus.SUCCESS;
}

return null;
},
},
mounted() {
this.preferredValidator.$touch();
},
};
</script>
```

And we use like normal

```vue
<form-group
:validator="$v.form.email"
:attribute="Email with wrapper"
>
<a-input
v-model="form.email"
slot-scope="{ attrs, listeners }"
v-bind="attrs"
v-on="listeners"
/>
</form-group>
```

### Live Ant Design Vue example

<iframe src="https://codesandbox.io/s/vuelidate-error-extractor-ant-design-vue-0ouk9" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>