1
0
mirror of synced 2024-11-28 16:16:09 +03:00
vue-formulario/README.md

96 lines
2.5 KiB
Markdown
Raw Normal View History

2020-05-22 14:21:54 +03:00
## What is Vue Formulario?
2021-06-13 00:30:19 +03:00
Vue Formulario is a library, inspired by <a href="https://vueformulate.com">Vue Formulate</a>, that handles the core logic
2020-11-10 10:24:31 +03:00
for working with forms and gives full control on the form presentation.
2020-05-22 14:21:54 +03:00
## Examples
Every form control have to rendered inside FormularioField component. This component provides `id` and `context` in
2020-11-10 10:24:31 +03:00
v-slot props. Control should use `context.model` as v-model and `context.runValidation` as handler for `blur` event
(it is necessary for validation when property `validationBehavior` is `demand`). Errors list for a field can be
accessed through `context.allErrors`.
2020-05-22 14:21:54 +03:00
2020-05-22 14:35:52 +03:00
The example below creates the authorization form from data:
2020-05-22 14:21:54 +03:00
```json
2020-11-10 10:24:31 +03:00
{
"username": "",
"password": "",
"options": {
"anonymous": false,
"tags": ["test"]
2020-05-22 14:21:54 +03:00
}
2020-11-10 10:24:31 +03:00
}
2020-05-22 14:21:54 +03:00
```
```html
2020-11-10 10:24:31 +03:00
<FormularioForm
v-model="formData"
name="formName"
>
<FormularioField
2020-11-10 10:24:31 +03:00
v-slot="{ context }"
name="username"
validation="required|email"
validation-behavior="live"
2020-05-22 14:21:54 +03:00
>
2020-11-10 10:24:31 +03:00
<input
v-model="context.model"
type="text"
@blur="context.runValidation"
2020-05-22 14:21:54 +03:00
>
2020-11-10 10:24:31 +03:00
<div v-if="context.allErrors.length > 0">
<span
v-for="(error, index) in context.allErrors"
:key="index"
2020-05-22 14:21:54 +03:00
>
2020-11-10 10:24:31 +03:00
{{ error }}
</span>
</div>
</FormularioField>
2020-05-22 14:21:54 +03:00
<FormularioField
2020-11-10 10:24:31 +03:00
v-slot="{ context }"
name="password"
validation="required|min:4,length"
>
<input
v-model="context.model"
type="password"
2020-05-22 14:21:54 +03:00
>
</FormularioField>
2020-05-22 14:21:54 +03:00
<FormularioFieldGroup name="options">
<FormularioField
2020-11-10 10:24:31 +03:00
v-slot="{ context }"
name="anonymous"
2020-05-22 14:21:54 +03:00
>
2020-11-10 10:24:31 +03:00
<div>
<input
id="options-anonymous"
v-model="context.model"
type="checkbox"
>
<label for="options-anonymous">As anonymous</label>
</div>
</FormularioField>
</FormularioFieldGroup>
2020-11-10 10:24:31 +03:00
<FormularioField
2020-11-10 10:24:31 +03:00
v-slot="{ context }"
name="options.tags[0]"
>
<input
v-model="context.model"
type="text"
>
</FormularioField>
2020-11-10 10:24:31 +03:00
</FormularioForm>
2020-05-22 14:21:54 +03:00
```
## License
[MIT](https://opensource.org/licenses/MIT)
2020-05-22 14:37:44 +03:00
Copyright (c) 2020-present, [RetailDriver LLC](https://www.retailcrm.pro) <br>
2020-05-22 14:35:52 +03:00
Copyright (c) 2020-present, [Braid LLC](https://www.wearebraid.com/)