Skip to content

Commit 4fc286f

Browse files
authored
Merge pull request #196 from Jenesius/issue_193
Issue 193
2 parents faff9cc + 4f6b426 commit 4fc286f

File tree

17 files changed

+416
-105
lines changed

17 files changed

+416
-105
lines changed

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
#### 3.0.14 (2024-03-03)
2+
3+
##### Breaking Changes
4+
5+
* remove update-input-position.ts ([30ee8b1c](https://github.com/Jenesius/vue-form/commit/30ee8b1cedf17b5fbdba9fa2443ae64088f6b7e1))
6+
7+
##### Documentation Changes
8+
9+
* update `ru` info about input-select ([3c4350bb](https://github.com/Jenesius/vue-form/commit/3c4350bb1918d095679394fa23feddbea8cfc647))
10+
11+
##### New Features
12+
13+
* update move Up/Down. ([7d7f21fa](https://github.com/Jenesius/vue-form/commit/7d7f21fa508617eaf08a24db1efee4034ffe85be))
14+
15+
##### Tests
16+
17+
* modify tests, add input-select effect for Shift ([e6f3e9dc](https://github.com/Jenesius/vue-form/commit/e6f3e9dc47bbe24821d50fc8f1992a12b8958baa))
18+
119
#### 3.0.13 (2024-02-20)
220

321
##### New Features

docs/inputs/input-select.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,20 @@ according to the value in the `value` field of the passed `options`. Если у
8282
- Moving around the object is possible using `ArrowDown` and `ArrowUp`. Moving this way
8383
changes the value of a field.
8484
- Selecting an element is possible by clicking on the corresponding element.
85-
- **Cannot** select an element using `Enter` or `Space`.
86-
- Using `Enter` or `Space` expands or closes the dropdown list.
85+
- **Cannot** select an element using `Enter`.
86+
- Using `Enter` expands or closes the dropdown list.
8787
- An additional search controller is shown for a long list.
8888
- Blocking fields cancels navigation using `Tab`. There is also a change in the style of `select`.
8989
- If the validation fails, the field should change the style of the `select`.
9090
- При использовании аттрибута `multiple` выборка не должна закрывать выпадающий список.
91+
- In `miltiple:true` mode with `Shift` held down, the following transition order is used (`_` state value
92+
in which no element is selected, `->` - transition from one element to another, `0` - element not selected, `1` - element
93+
already selected):
94+
- _ -> 0 = _ , 1
95+
- 1 -> 0 = 1, 1
96+
- 1 -> 1 = 0, 1
97+
- 0 -> 0 = 1, 0
98+
- 0 -> 1 = 0, 0
9199

92100

93101
## Examples

docs/ru/inputs/input-select.md

+38-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ const values = useFormValues(form);
5353
- Тип `string`
5454

5555
В случае, если значение не выбрано - показывается текстовая метка.
56+
57+
### multiple <Badge type = "info">Optional</Badge>
58+
59+
- Type `boolean`
60+
61+
Данный параметр позволяет использовать множественную выборку. В таком случае modelValue будет обрабатываться как массив.
62+
63+
### limit <Badge type = "info">Optional</Badge>
64+
65+
- Type `number`
66+
67+
Данный параметр устанавливает предельное количество выбираемых элементов, если используется атрибут `multiple`.
68+
69+
5670
____
5771

5872
Так же все параметры, общие для всех `FormField`. Информацию о них можно посмотреть
@@ -69,12 +83,22 @@ ____
6983
- Перемещение по объекту возможна используя `ArrowDown` и `ArrowUp`. Перемещение таким способом
7084
изменяет значение поля.
7185
- Выбор элемента возможен по щелчку на соответствующий элемент.
72-
- **Нельзя** выбрать элемент используя `Enter` или `Space`.
73-
- Использование `Enter` или `Space` раскрывает или закрывает выпадающий список.
86+
- **Нельзя** выбрать элемент используя `Enter`.
87+
- Использование `Enter` раскрывает или закрывает выпадающий список.
7488
- Для длинного списка показывается дополнительный контроллер поиска.
7589
- Блокировка полей отменяет навигацию используя `Tab`. Также происходит изменение стилистики `select`.
7690
- При неудачной валидации поле должно изменить стилистику `select`.
77-
91+
- При использовании аттрибута `multiple` выборка не должна закрывать выпадающий список.
92+
- `Space` используется для выборки элементов.
93+
- В режиме `miltiple:true` с зажатой `Shift` используется следующий порядок переходов (`_` означение состояние
94+
в котором ни один элемент не выбран, `->` - переход с одного элемента на другой, `0` - элемент не выбран, `1` - элемент
95+
уже был выбран):
96+
- _ -> 0 = _ , 1
97+
- 1 -> 0 = 1 , 1
98+
- 1 -> 1 = 0 , 1
99+
- 0 -> 0 = 1 , 0
100+
- 0 -> 1 = 0 , 0
101+
78102
## Пример
79103

80104
Для подключения виджета необходимо указать `type` и `options`:
@@ -132,6 +156,17 @@ ____
132156
Использование `hiddenValues` и установка значения `['blue', 'purple', 'pink', 'brown', 'grey']`:
133157
<FormField :options = "colors" hiddenValues = "['blue', 'purple', 'pink', 'brown', 'grey']" type = "select" name = "color" label = "Отфильтрованные цвета" />
134158

159+
----
160+
161+
Использование `multiple`:
162+
<FormField :options = "colors" type = "select" name = "multiple-color" multiple label = "Multiple colors" />
163+
164+
----
165+
166+
Использование `limit` = `2` вместе с `multiple`:
167+
<FormField :options = "colors" type = "select" name = "multiple-color" multiple label = "Multiple colors" limit = "2" />
168+
169+
135170

136171
----
137172
Текущее состояние формы:

examples/input-select/App.vue

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
<template>
22
<div class="container">
3-
<div>
4-
<h2>Values</h2>
5-
<pre class="container-values">{{ JSON.stringify(values, undefined, 4) }}</pre>
6-
</div>
3+
74

85
<div class="wrap-app ">
6+
<select name="select">
7+
<!--Supplement an id here instead of using 'name'-->
8+
<option value="value1">Значение 1</option>
9+
<option value="value2" >Значение 2</option>
10+
<option value="value3">Значение 3</option>
11+
<option value="value3">Значение 4</option>
12+
<option value="value3">Значение 5</option>
13+
</select>
14+
<select name="select" multiple size =10>
15+
<!--Supplement an id here instead of using 'name'-->
16+
<option value="value1">Значение 1</option>
17+
<option value="value2">Значение 2</option>
18+
<option value="value3">Значение 3</option>
19+
<option value="value3">Значение 4</option>
20+
<option value="value3">Значение 5</option>
21+
<option value="value3">Значение 6</option>
22+
<option value="value3">Значение 7</option>
23+
<option value="value3">Значение 8</option>
24+
<option value="value3">Значение 9</option>
25+
</select>
926
<input-field type="select" name = "sex" :options = "sexOptions"/>
1027
<input-field type = "select" name = "language" :options = "languageOptions"/>
1128
<input-field type = "select" name = "languages" :options = "languageOptions" multiple label = "Multi languages"/>
@@ -19,6 +36,10 @@
1936

2037
<button class="button" @click="form.cleanValues()">Clean Form</button>
2138
</div>
39+
<div>
40+
<h2>Values</h2>
41+
<pre class="container-values">{{ JSON.stringify(values, undefined, 4) }}</pre>
42+
</div>
2243
</div>
2344
</template>
2445

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jenesius-vue-form",
3-
"version": "3.0.13",
3+
"version": "3.0.14",
44
"description": "Heavy form system for Vue.js",
55
"main": "dist/jenesius-vue-form.cjs.js",
66
"module": "dist/jenesius-vue-form.es.js",

src/classes/Form.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,13 @@ export default class Form extends EventEmitter implements FormDependence {
407407
unsubscribe(element: any) {
408408
this.dependencies.remove(element);
409409
}
410-
410+
411+
/**
412+
*
413+
* @param name - tracked field
414+
* @param callback
415+
* @description The method fires every time the given field has been changed.
416+
*/
411417
oninput(name: string, callback: (newValue: any) => void) {
412418
return this.on(Form.getEventValueByName(name), callback)
413419
}

src/debug/warn.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import debug from "./debug";
2-
31
export default function warn(subject: string, text: string, error?: any) {
42
console.log(`%c[${subject}] %c${text}`, 'color: #dac400', 'color: black',error);
53
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {OptionRow} from "../types";
2+
3+
/**
4+
* @description Метод возвращает OptionRow элемента, который будет являться проецирование duration на текущий элемент.
5+
* @param options Массив всех опций
6+
* @param currentValue Текущее значение
7+
* @param duration Величина смещения
8+
*/
9+
export default function getOptionRowByDuration(options: OptionRow[], currentValue: unknown, duration: number) {
10+
let index = options.findIndex(item => item.value === currentValue) ;
11+
index = index === -1 ? duration > 0 ? -1 : 0 : index;
12+
index = index + duration;
13+
14+
if (index < 0) index = options.length + index;
15+
16+
return options[index % options.length];
17+
}

src/utils/update-input-position.ts

-20
This file was deleted.

src/utils/utils.ts

-5
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ import runPromiseQueue from "./run-promise-queue";
2929
import splitName from "./split-name";
3030

3131

32-
import updateInputPosition from "./update-input-position";
33-
34-
35-
3632
const utils = {
3733
bypassObject,
3834
checkCompositeName,
@@ -64,6 +60,5 @@ const utils = {
6460
replaceValues,
6561
runPromiseQueue,
6662
splitName,
67-
updateInputPosition,
6863
}
6964
export default utils;

src/widgets/form-field.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
:disabled = "input?.disabled || $attrs['disabled'] || false"
1111
:changed = "input?.changed"
1212
:errors="input?.errors || []"
13-
:options="parseOptions(options)"
13+
:options="parseOptions(options || [])"
1414
/>
1515
</template>
1616

src/widgets/inputs/input-radio/widget-input-radio.vue

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import FieldWrap from "../field-wrap.vue";
2525
import {OptionRow} from "../../../types";
2626
import ElementInputRadio from "./element-input-radio.vue";
2727
import {nextTick, ref} from "vue";
28-
import updateInputPosition from "../../../utils/update-input-position";
28+
import getOptionRowByDuration from "../../../utils/get-option-row-by-duration";
2929
3030
const props = defineProps<{
3131
label?: string,
@@ -53,8 +53,9 @@ function getTabindex(index: number) {
5353
}
5454
5555
function handleMove(duration: number) {
56-
57-
updateInputPosition({options: props.options, value: props.modelValue || props.options[0].value, onInput, duration});
56+
onInput(
57+
getOptionRowByDuration( props.options, props.modelValue || props.options[0].value, duration).value
58+
)
5859
focusActiveItem()
5960
}
6061

0 commit comments

Comments
 (0)