alchemy-form 0.3.0-alpha.4 → 0.3.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/assets/stylesheets/form/elements/_datetime.scss +6 -0
- package/assets/stylesheets/form/elements/index.scss +1 -0
- package/element/al_datetime_input.js +127 -0
- package/package.json +1 -1
- package/view/form/inputs/edit/date.hwk +13 -13
- package/view/form/inputs/edit/datetime.hwk +13 -20
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The al-datetime-input:
|
|
3
|
+
* Populate an input on the browser-side with correct timezone info
|
|
4
|
+
*
|
|
5
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
6
|
+
* @since 0.3.0
|
|
7
|
+
* @version 0.3.0
|
|
8
|
+
*/
|
|
9
|
+
const DatetimeInput = Function.inherits('Alchemy.Element.Form.Base', 'DatetimeInput');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get/set the mode
|
|
13
|
+
*
|
|
14
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
15
|
+
* @since 0.3.0
|
|
16
|
+
* @version 0.3.0
|
|
17
|
+
*/
|
|
18
|
+
DatetimeInput.setAttribute('datemode', null, function setMode(datemode) {
|
|
19
|
+
this.populateInputWithValue(this.value, datemode);
|
|
20
|
+
return datemode;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get/set the value
|
|
25
|
+
*
|
|
26
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
27
|
+
* @since 0.3.0
|
|
28
|
+
* @version 0.3.0
|
|
29
|
+
*/
|
|
30
|
+
DatetimeInput.setAttribute('value', null, function setValue(value) {
|
|
31
|
+
return this.populateInputWithValue(value, this.datemode);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Set the value with a function call
|
|
36
|
+
*
|
|
37
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
38
|
+
* @since 0.3.0
|
|
39
|
+
* @version 0.3.0
|
|
40
|
+
*/
|
|
41
|
+
DatetimeInput.setMethod(function setValue(value) {
|
|
42
|
+
this.value = value;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Revalidate the value
|
|
47
|
+
*
|
|
48
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
49
|
+
* @since 0.3.0
|
|
50
|
+
* @version 0.3.0
|
|
51
|
+
*
|
|
52
|
+
* @return {Object[]}
|
|
53
|
+
*/
|
|
54
|
+
DatetimeInput.setMethod(function populateInput() {
|
|
55
|
+
return this.populateInputWithValue(this.value, this.datemode);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Revalidate the value
|
|
60
|
+
*
|
|
61
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
62
|
+
* @since 0.3.0
|
|
63
|
+
* @version 0.3.0
|
|
64
|
+
*
|
|
65
|
+
* @return {Object[]}
|
|
66
|
+
*/
|
|
67
|
+
DatetimeInput.setMethod(function populateInputWithValue(value, datemode) {
|
|
68
|
+
|
|
69
|
+
let iso_date,
|
|
70
|
+
date;
|
|
71
|
+
|
|
72
|
+
if (value) {
|
|
73
|
+
date = Date.create(value);
|
|
74
|
+
iso_date = date.toISOString();
|
|
75
|
+
} else {
|
|
76
|
+
iso_date = '';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
value = iso_date;
|
|
80
|
+
|
|
81
|
+
if (Blast.isServer) {
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (arguments.length == 1) {
|
|
86
|
+
datemode = this.datemode;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let input = this.querySelector('input');
|
|
90
|
+
|
|
91
|
+
if (!datemode) {
|
|
92
|
+
datemode = 'datetime';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!input) {
|
|
96
|
+
input = this.createElement('input');
|
|
97
|
+
input.setAttribute('type', datemode + '-local');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!value) {
|
|
101
|
+
input.value = '';
|
|
102
|
+
return '';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let formatted;
|
|
106
|
+
|
|
107
|
+
if (datemode == 'date') {
|
|
108
|
+
formatted = date.format('Y-m-d');
|
|
109
|
+
} else {
|
|
110
|
+
formatted = date.format('Y-m-d\\TH:i:s');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
input.value = formatted;
|
|
114
|
+
|
|
115
|
+
return iso_date;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Added to the DOM
|
|
120
|
+
*
|
|
121
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
122
|
+
* @since 0.3.0
|
|
123
|
+
* @version 0.3.0
|
|
124
|
+
*/
|
|
125
|
+
DatetimeInput.setMethod(function introduced() {
|
|
126
|
+
this.populateInput();
|
|
127
|
+
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
>
|
|
1
|
+
<al-datetime-input
|
|
2
|
+
datemode="date"
|
|
3
|
+
>
|
|
4
|
+
<% $0.setValue(value) %>
|
|
5
|
+
<input
|
|
6
|
+
value=<% value %>
|
|
7
|
+
class="alchemy-field-value"
|
|
8
|
+
type="date"
|
|
9
|
+
form=<% form_id %>
|
|
10
|
+
name=<% path %>
|
|
11
|
+
pattern="\d{4}-\d{2}-\d{2}"
|
|
12
|
+
>
|
|
13
|
+
</al-datetime-input>
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
value=<% value %>
|
|
15
|
-
class="alchemy-field-value"
|
|
16
|
-
type="datetime-local"
|
|
17
|
-
form=<% form_id %>
|
|
18
|
-
name=<% path %>
|
|
19
|
-
pattern="\d{4}-\d{2}-\d{2} \d{1,2}:\d{1,2}(?::\d{1,2})?"
|
|
20
|
-
>
|
|
1
|
+
<al-datetime-input
|
|
2
|
+
datemode="datetime"
|
|
3
|
+
>
|
|
4
|
+
<% $0.setValue(value) %>
|
|
5
|
+
<input
|
|
6
|
+
class="alchemy-field-value"
|
|
7
|
+
type="datetime-local"
|
|
8
|
+
form=<% form_id %>
|
|
9
|
+
name=<% path %>
|
|
10
|
+
pattern="\d{4}-\d{2}-\d{2} \d{1,2}:\d{1,2}(?::\d{1,2})?"
|
|
11
|
+
value=""
|
|
12
|
+
>
|
|
13
|
+
</al-datetime-input>
|