Skip to content

Commit 691210e

Browse files
authored
Merge pull request #192 from Jenesius/issue_191
Issue 191
2 parents 34cb35b + d61294e commit 691210e

File tree

16 files changed

+228
-77
lines changed

16 files changed

+228
-77
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
#### 3.0.12 (2024-02-01)
2+
3+
##### Documentation Changes
4+
5+
* add new information about 'handlers' of input-date. ([58780903](https://github.com/Jenesius/vue-form/commit/5878090358916863dcaea5e87b12b9eac3cd42a7))
6+
7+
##### New Features
8+
9+
* add widgets prop for main import ([649e5f80](https://github.com/Jenesius/vue-form/commit/649e5f802c6e6edbf600cd85dffcb418d7cdc7fe))
10+
11+
##### Bug Fixes
12+
13+
* update handlers for input-date. Add new tests. ([64826cf3](https://github.com/Jenesius/vue-form/commit/64826cf3c4c48e715e9bcb9093d041a43109fd4b))
14+
* update version to 3.0.9. Add DateController. Add handlers for input-date ([c3d5f1d6](https://github.com/Jenesius/vue-form/commit/c3d5f1d6f2e56477b5700d21c8f8208c380afc9b))
15+
* update version to 3.0.8 ([139c8958](https://github.com/Jenesius/vue-form/commit/139c8958ba45286f9bd94bea5a334f27aa692d12))
16+
* update vue version ([34cb35b8](https://github.com/Jenesius/vue-form/commit/34cb35b89b6cbaa32e10eb9cff58892726236323))
17+
118
#### 3.0.6 (2023-12-09)
219

320
##### Bug Fixes

docs/inputs/input-date.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,36 @@ String label, displayed when there is no data in the field.
2828
The mask sets the date display format. The mask can consist of characters of any character, however
2929
keywords are `Y`, `M`, `D`, `H` and `h`. The corresponding values will be substituted for their position.
3030

31+
### handlers
32+
- Type: 'array'
33+
- By default: `[]`.
34+
35+
An array of handlers that can be used to enter fields. The array must consist of two elements. First
36+
It is a handler of form model values of the “Date” type. The second handler is a converter from strings(values,
37+
located inside the input fields) in the value that needs to be stored in the model data form.
38+
39+
#### Example
40+
41+
```vue
42+
43+
<template>
44+
<FormField type="date" :handlers="[handlerForm, handlerTo]" mask = "YYYY-MM-DD HH"/>
45+
</template>
46+
<script setup>
47+
import {DateController} from "jenesius-vue-form";
48+
49+
function handlerFrom(formValue) {
50+
return new Date(formValue)
51+
}
52+
53+
function handlerTo(strValue) {
54+
return DateController.ConvertToDate(strValue, 'YYYY-MM-DD HH').toISOString()
55+
}
56+
</script>
57+
```
58+
In the current example, we have set a new mask for this field, and also defined handlers to convert the value to
59+
ISO date format.
60+
3161
____
3262

3363
Also, all parameters common to all `FormField`. Information about them can be found on [this page](./form-field.md#params).

docs/ru/inputs/input-date.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,34 @@ const values = useFormValues(form)
2828
Маска задаёт формат отображение даты. Маска может состоять из символов любых символов, однако
2929
ключевыми являются `Y`, `M`, `D`, `H` и `h`. На их позицию будут подставлены соотвествующие значений.
3030

31+
### handlers
32+
- Тип: 'array'
33+
34+
Массив обработчиков, которые можно применить к значению поля ввода. Массив должен состоять из двух элементов. Первый
35+
является обработчиком значения из модели форму к типу `Date`. Второй обработчик является конвертером из строки(значения,
36+
находящееся внутри поля ввода) в значение, которое необходимо хранить в модели данных формы.
37+
38+
#### Example
39+
40+
```vue
41+
42+
<template>
43+
<FormField type="date" :handlers="[handlerForm, handlerTo]" mask = "YYYY-MM-DD HH"/>
44+
</template>
45+
<script setup>
46+
import {DateController} from "jenesius-vue-form";
47+
48+
function handlerFrom(formValue) {
49+
return new Date(formValue)
50+
}
51+
52+
function handlerTo(strValue) {
53+
return DateController.ConvertToDate(strValue, 'YYYY-MM-DD HH').toISOString()
54+
}
55+
</script>
56+
```
57+
В текущем примере мы установили новую маску для данного поля, а также определили обработчики для конвертации значения в
58+
ISO формат даты.
3159
____
3260

3361
Так же все параметры, общие для всех `FormField`. Информацию о них можно посмотреть на [этой странице](./form-field.md#params).

examples/all-inputs/App.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<input-field name = "birthday" type = "date" label = "Disabled" disabled/>
3232
<input-field name = "birthday" type = "date" label = "With Error" :errors = "['Some mistake']"/>
3333
<input-field name = "birthday" type = "date" label = "Placeholder" placeholder = "Add your birthday." />
34+
<input-field name = "birthday" type = "date" label = "Other mask" mask = "DD/MM/YYYY"/>
3435

3536
<h2>Input Tel</h2>
3637
<input-field name = "phone" type = "tel"/>
@@ -117,6 +118,8 @@
117118
import {Form, InputField} from "../../src/index";
118119
119120
const form = new Form();
121+
// @ts-ignore
122+
window.form = form;
120123
function modifyOnlyChar(a: string) {
121124
return a.replace(/\d/g, '');
122125
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

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

project/pages/test/App.vue

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,27 @@
66
<div :key = "pureValue">Pure values: {{pureValue}}</div>
77
<div :key = "pureAvailabilities">Pure av: {{pureAvailabilities}}</div>
88

9-
<form-field type = "native-date" name = "create" />
10-
11-
<br>
12-
13-
14-
<button @click = "change">change field name</button>
15-
<button @click = "clean">clean values</button>
16-
17-
<button @click = "setDefaultValues">set default values</button>
9+
<input-field name = "birthday" type = "date" label = "Placeholder" />
1810

11+
<input-field name = "birthday" type = "date" label = "Other mask" mask = "MM/DD/YYYY" :handlers = "[testFrom, testTo]"/>
1912

2013

2114
</div>
2215
</template>
2316

2417
<script setup lang='ts'>
2518
import Form from "../../../src/classes/Form";
26-
import FormField from "./../../../src/widgets/form-field.vue";
27-
import {computed, ref} from "vue";
28-
import WidgetAddress from "./widget-address.vue"
19+
import {ref} from "vue";
2920
import copyObject from "./../../../src/utils/copy-object";
21+
import {InputField} from "../../../src/index";
22+
import DateController from "../../../src/controllers/date-controller";
3023
3124
// @ts-ignore
3225
const form = window.form = new Form({
3326
name: "main",
3427
parent:false
3528
});
3629
const show = ref(false);
37-
const labelButton = computed(() => show.value ? 'Hide' : 'Show')
3830
3931
setInterval(() => {
4032
if (!form) return;
@@ -61,12 +53,21 @@ function change() {
6153
function clean() {
6254
form.cleanValues();
6355
}
64-
function setDefaultValues() {
65-
return form.cleanValues({
66-
username: "Jenesius",
67-
"coordinate.x": "123"
68-
})
56+
57+
function testFrom(date: unknown) {
58+
if (typeof date !== 'string') return null;
59+
return new Date(date)
60+
}
61+
62+
function testTo(str?: string) {
63+
if (typeof str !== 'string') return null;
64+
65+
const p = DateController.ConvertToDate(str, "MM/DD/YYYY");
66+
if (!p) return null;
67+
68+
return DateController.GetPrettyDate(p, 'YYYY-MM-DD')
6969
}
70+
7071
</script>
7172

7273
<style>

project/pages/test/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ config({
1818
'local-date': InputTestDateLocal,
1919
'native-date': InputNativeDate
2020
},
21-
debug: true
21+
// debug: true
2222
})
2323

2424
createApp(App).mount('#app')

src/config/config.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
import mergeObjects from "./../utils/merge-objects";
21
import STORE, {IStore} from "./store";
3-
import Store from "./store";
4-
import debug from "./../debug/debug";
2+
import widgets from "./widgets";
53

64
export default function config(params: ConfigParams) {
75

8-
/**
9-
* In case if params includes inputTypes, merge provided component with default widgets.
10-
*/
6+
Object.assign(STORE, params);
7+
8+
STORE.inputTypes = {
9+
...widgets,
10+
...(params.inputTypes || {}),
11+
}
12+
13+
if (STORE.typeNotCaseSensitive)
14+
STORE.inputTypes = Object.entries(STORE.inputTypes).reduce<Record<string, any>>((acc, [type, component]) => {
15+
acc[type.toLowerCase()] = component
16+
return acc;
17+
}, {})
18+
19+
return;
20+
21+
/*
22+
// In case if params includes inputTypes, merge provided component with default widgets.
1123
if ("typeNotCaseSensitive" in params && typeof params.typeNotCaseSensitive === "boolean") Store.typeNotCaseSensitive = params.typeNotCaseSensitive;
1224
1325
@@ -34,6 +46,11 @@ export default function config(params: ConfigParams) {
3446
} catch (e) {
3547
console.error(e)
3648
}
49+
50+
if (params.date) {
51+
mergeObjects(STORE.date, params.date);
52+
}
53+
*/
3754
}
3855

3956
type ConfigParams = Partial<IStore> & {

src/config/store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const STORE: IStore = {
99
debug: false,
1010
defaultType: 'text',
1111
cleanValue: null,
12+
dateMask: "DD/MM/YYYY",
1213
date: {
13-
dateMask: "YYYY/MM/DD",
1414
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
1515
daysWeek: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
1616
calendar: {
@@ -34,8 +34,8 @@ export interface IStore {
3434
debug: boolean,
3535
defaultType: string,
3636
cleanValue: any,
37+
dateMask: string,
3738
date: {
38-
dateMask: string,
3939
months: string[],
4040
daysWeek: string[],
4141
calendar: {

0 commit comments

Comments
 (0)