Skip to content

Commit edc8d09

Browse files
committed
docs: add information about new prop 'changed'. Add info about converting options.
1 parent e42b936 commit edc8d09

File tree

4 files changed

+88
-28
lines changed

4 files changed

+88
-28
lines changed

docs/.vitepress/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function sidebar() {
6363
{
6464
text: "Best Practices",
6565
items: [
66-
{ text: "Depth information", link: "/guide/form-in-depth" }
66+
{ text: "Depth information", link: "/guide/form-in-depth" },
67+
{ text: 'Converting Options', link: "/utils/convert-options-object" }
6768
]
6869
},
6970

docs/guide/custom-widgets.md

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,20 @@ overwrite part of it. This method is described [here](/guide/configuration#input
1010
Any *props* passed will also be passed to your component.
1111
But! There are some differences worth mentioning:
1212

13-
### options
14-
Options will **always** be cast as follows:
13+
- **options** Array of options, used for select/radio. Read more [here](/utils/convert-options-object). The data undergoes additional transformation and always has a place to be:
1514

16-
```json
17-
[
18-
{
19-
"title": "Title", "value": 1
20-
},
21-
{
22-
"title": "Jenesius", "value": 2
23-
}
24-
]
25-
```
26-
27-
### disabled and errors
28-
These properties will be internal, they can be overridden, but then the form will not be able to
29-
influence them:
30-
```html
31-
<input-field disabled name = "input"/>
32-
```
3315
```ts
34-
form.enable('input'); // Not working
35-
```
36-
Similarly, with `errors`, in this case the `validate` method will not be able to show errors.
16+
type Options = Array<{
17+
label: string,
18+
value: any
19+
}>
20+
3721

38-
----
39-
This is where the restrictions end. If this method or restrictions are not allowed
40-
for your project, you can use the following method.
22+
23+
```
24+
- **disabled** Will be dynamically pulled from the form. Changed using *disable/enable* methods
25+
- **errors** Is an array of strings
26+
- **changed** Dynamically pulled out of the mold. True - if the field is marked as modified in the form.
4127

4228
## Own Components
4329

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,76 @@
11
# Convert options object
22

3-
Здесь будет описано трансформация options.
3+
For better compatibility with previous solutions, as well as ease of development, the options property can be
4+
two kinds:
5+
6+
## Object
7+
This view is an object with **value** on the left and **label** on the right. For example
8+
country enumeration has been selected:
9+
```ts
10+
const options = {
11+
'en': 'Great Britain',
12+
'us': 'United States',
13+
'jp': 'Japan',
14+
'ru': 'Russia'
15+
}
16+
```
17+
18+
:::tip Why Value on left side?
19+
Primarily because the value must be unique. Because object is used for
20+
simple variants of this property was the most significant.
21+
:::
22+
23+
The disadvantage of this approach is that the value can only be a string. **Important** to remember that
24+
even a numeric property will be converted to a string.
25+
26+
## Array based
27+
This method is more flexible, because allows you to set any data to the value. In this case, *options*
28+
takes the following form:
29+
```ts
30+
const options = [
31+
{ value: 'en', label: 'Great Britain' },
32+
{ value: 'us', label: 'United States' },
33+
{ value: 'jp', label: 'Japan' },
34+
{ value: 'ru', label: 'Russia' },
35+
]
36+
```
37+
This method is more cumbersome than the first, but more flexible, because now we can use the following:
38+
```ts
39+
const options = [
40+
{
41+
value: { code: 1, mark: 'en' }, label: 'Great Britain'
42+
}
43+
]
44+
```
45+
46+
## Converting
47+
48+
When using **input-field** remember that you will always get options as an output as an array!
49+
This is easier to show with an example:
50+
51+
```vue
52+
53+
<template>
54+
<input-field :options = "data" type = "custom-input"/>
55+
</template>
56+
<script setup>
57+
import {InputField} from "./index";
58+
const data = {
59+
'1': 'M',
60+
'2': 'W'
61+
}
62+
</script>
63+
```
64+
```vue
65+
<!--custom-input-->
66+
<div>
67+
{{options}}
68+
</div>
69+
<script setup>
70+
const props = defineProps({
71+
options: Array
72+
})
73+
74+
props.options; // [ { value: '1', label: 'M' }, { value: '2', label: 'W' } ]
75+
</script>
76+
```

plugin/widgets/input-field.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
:modelValue="props.name ? state.value : modelValue"
77
@update:modelValue="handleInput"
88

9-
:label="props.label"
9+
:label="label"
1010
:disabled="state.disabled"
1111
:errors="state.errors"
1212
:options="parseOptions(options)"

0 commit comments

Comments
 (0)