alchemy-form 0.2.1 → 0.2.3
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 +15 -0
- package/controller/form_api_controller.js +25 -3
- package/element/al_button.js +2 -2
- package/element/al_field.js +9 -0
- package/element/al_form.js +26 -12
- package/element/al_select.js +35 -16
- package/element/al_table.js +2 -3
- package/package.json +2 -2
- package/view/form/inputs/edit/has_one_parent.hwk +7 -0
- package/view/form/inputs/edit/string.hwk +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## 0.2.3 (2023-02-11)
|
|
2
|
+
|
|
3
|
+
* Use `Scene#pushToHistory()` instead of directly calling `pushState`
|
|
4
|
+
* Select `display_field_select` fields when requesting related data
|
|
5
|
+
* Make local-filtering in `al-select` elements case insensitive
|
|
6
|
+
* Fix `al-select` never getting more than the first page in `getRemoteFetchConfig` method
|
|
7
|
+
* Add `hasOneParent` field support
|
|
8
|
+
* Make `FormApi#related()` action make sure fields exist before querying them
|
|
9
|
+
* Add a workaround so `al-select` actually refreshes elements when removing the search value
|
|
10
|
+
|
|
11
|
+
## 0.2.2 (2023-01-23)
|
|
12
|
+
|
|
13
|
+
* Fix `al-button`'s `activate` event not being cancelable
|
|
14
|
+
* Add `placeholder` support to the string field
|
|
15
|
+
|
|
1
16
|
## 0.2.1 (2022-12-23)
|
|
2
17
|
|
|
3
18
|
* Enable `al-form` model validation
|
|
@@ -17,7 +17,7 @@ const FormApi = Function.inherits('Alchemy.Controller', 'FormApi');
|
|
|
17
17
|
*
|
|
18
18
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
19
19
|
* @since 0.1.0
|
|
20
|
-
* @version 0.
|
|
20
|
+
* @version 0.2.3
|
|
21
21
|
*
|
|
22
22
|
* @param {Conduit} conduit
|
|
23
23
|
*/
|
|
@@ -34,16 +34,34 @@ FormApi.setAction(async function related(conduit) {
|
|
|
34
34
|
if (config.value) {
|
|
35
35
|
crit.where(model.primary_key).equals(config.value);
|
|
36
36
|
} else if (config.search) {
|
|
37
|
-
let display_fields = Array.cast(model.
|
|
37
|
+
let display_fields = Array.cast(model.display_field),
|
|
38
|
+
search_fields = [];
|
|
38
39
|
|
|
39
40
|
let or = crit.or();
|
|
40
41
|
let rx = RegExp.interpretWildcard('*' + body.config.search + '*', 'i');
|
|
41
42
|
|
|
42
43
|
for (let field of display_fields) {
|
|
43
|
-
if (!field) {
|
|
44
|
+
if (!field || !model.getField(field)) {
|
|
44
45
|
continue;
|
|
45
46
|
}
|
|
47
|
+
search_fields.push(field);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!search_fields.length) {
|
|
51
|
+
if (model.getField('title')) {
|
|
52
|
+
search_fields.push('title');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (model.getField('name')) {
|
|
56
|
+
search_fields.push('name');
|
|
57
|
+
}
|
|
46
58
|
|
|
59
|
+
if (model.getField('slug')) {
|
|
60
|
+
search_fields.push('slug');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (let field of search_fields) {
|
|
47
65
|
or.where(field).equals(rx);
|
|
48
66
|
}
|
|
49
67
|
}
|
|
@@ -52,6 +70,10 @@ FormApi.setAction(async function related(conduit) {
|
|
|
52
70
|
crit.page(config.page);
|
|
53
71
|
}
|
|
54
72
|
|
|
73
|
+
if (model.display_field_select) {
|
|
74
|
+
crit.select(model.display_field_select);
|
|
75
|
+
}
|
|
76
|
+
|
|
55
77
|
let records = await model.find('all', crit);
|
|
56
78
|
|
|
57
79
|
let result = {
|
package/element/al_button.js
CHANGED
|
@@ -66,7 +66,7 @@ Button.setAssignedProperty('action_instance');
|
|
|
66
66
|
*
|
|
67
67
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
68
68
|
* @since 0.2.0
|
|
69
|
-
* @version 0.2.
|
|
69
|
+
* @version 0.2.2
|
|
70
70
|
*/
|
|
71
71
|
Button.setMethod(function activate() {
|
|
72
72
|
|
|
@@ -82,7 +82,7 @@ Button.setMethod(function activate() {
|
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
let event = this.emit('activate');
|
|
85
|
+
let event = this.emit('activate', {cancelable: true});
|
|
86
86
|
|
|
87
87
|
if (event.defaultPrevented) {
|
|
88
88
|
return;
|
package/element/al_field.js
CHANGED
|
@@ -88,6 +88,15 @@ Field.setAttribute('readonly', {boolean: true});
|
|
|
88
88
|
*/
|
|
89
89
|
Field.setAssignedProperty('widget_settings');
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* The placeholder
|
|
93
|
+
*
|
|
94
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
95
|
+
* @since 0.2.2
|
|
96
|
+
* @version 0.2.2
|
|
97
|
+
*/
|
|
98
|
+
Field.setAttribute('placeholder');
|
|
99
|
+
|
|
91
100
|
/**
|
|
92
101
|
* Get the parent al-form element
|
|
93
102
|
*
|
package/element/al_form.js
CHANGED
|
@@ -153,12 +153,37 @@ Form.setMethod(Hawkejs.SERIALIZE_FORM, function serializeForm() {
|
|
|
153
153
|
*
|
|
154
154
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
155
155
|
* @since 0.1.0
|
|
156
|
-
* @version 0.2.
|
|
156
|
+
* @version 0.2.2
|
|
157
157
|
*/
|
|
158
158
|
Form.setMethod(async function submit() {
|
|
159
159
|
|
|
160
160
|
let result;
|
|
161
161
|
|
|
162
|
+
await this.validate();
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
result = await hawkejs.scene.onFormSubmit(this, null, {render_error: false});
|
|
166
|
+
} catch (err) {
|
|
167
|
+
if (err instanceof Classes.Alchemy.Error.Validation) {
|
|
168
|
+
this.showError(err);
|
|
169
|
+
} else {
|
|
170
|
+
this.showError(err);
|
|
171
|
+
throw err;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return result;
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Validate this form
|
|
180
|
+
*
|
|
181
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
182
|
+
* @since 0.2.2
|
|
183
|
+
* @version 0.2.2
|
|
184
|
+
*/
|
|
185
|
+
Form.setMethod(async function validate() {
|
|
186
|
+
|
|
162
187
|
if (this.model) {
|
|
163
188
|
let model = alchemy.getModel(this.model);
|
|
164
189
|
|
|
@@ -174,17 +199,6 @@ Form.setMethod(async function submit() {
|
|
|
174
199
|
}
|
|
175
200
|
}
|
|
176
201
|
|
|
177
|
-
try {
|
|
178
|
-
result = await hawkejs.scene.onFormSubmit(this, null, {render_error: false});
|
|
179
|
-
} catch (err) {
|
|
180
|
-
if (err instanceof Classes.Alchemy.Error.Validation) {
|
|
181
|
-
this.showError(err);
|
|
182
|
-
} else {
|
|
183
|
-
throw err;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return result;
|
|
188
202
|
});
|
|
189
203
|
|
|
190
204
|
/**
|
package/element/al_select.js
CHANGED
|
@@ -924,12 +924,12 @@ AlchemySelect.setMethod(function _processResponseList(list, page) {
|
|
|
924
924
|
*
|
|
925
925
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
926
926
|
* @since 0.2.0
|
|
927
|
-
* @version 0.2.
|
|
927
|
+
* @version 0.2.3
|
|
928
928
|
*/
|
|
929
929
|
AlchemySelect.setMethod(function getRemoteFetchConfig() {
|
|
930
930
|
|
|
931
931
|
// Don't perform request when everything has already been loaded
|
|
932
|
-
if (this.
|
|
932
|
+
if (this.loaded_item_count >= this.total_item_count) {
|
|
933
933
|
return;
|
|
934
934
|
}
|
|
935
935
|
|
|
@@ -970,7 +970,7 @@ AlchemySelect.setMethod(function applyFetchedData(err, result, config) {
|
|
|
970
970
|
*
|
|
971
971
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
972
972
|
* @since 0.1.0
|
|
973
|
-
* @version 0.
|
|
973
|
+
* @version 0.2.3
|
|
974
974
|
*/
|
|
975
975
|
AlchemySelect.setMethod(function recreateDropdownElements() {
|
|
976
976
|
|
|
@@ -979,10 +979,12 @@ AlchemySelect.setMethod(function recreateDropdownElements() {
|
|
|
979
979
|
|
|
980
980
|
Hawkejs.removeChildren(this.dropdown_content);
|
|
981
981
|
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
982
|
+
if (items && typeof items.keys == 'function') {
|
|
983
|
+
for (let key of items.keys()) {
|
|
984
|
+
item = items.get(key);
|
|
985
|
+
item = this._makeOption(item.id, item);
|
|
986
|
+
this.addToDropdown(item);
|
|
987
|
+
}
|
|
986
988
|
}
|
|
987
989
|
|
|
988
990
|
this.refreshResultAmount();
|
|
@@ -1667,7 +1669,7 @@ AlchemySelect.setMethod(function onTypeAreaKeydown(e, is_input) {
|
|
|
1667
1669
|
*
|
|
1668
1670
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
1669
1671
|
* @since 0.1.0
|
|
1670
|
-
* @version 0.
|
|
1672
|
+
* @version 0.2.3
|
|
1671
1673
|
*/
|
|
1672
1674
|
AlchemySelect.setMethod(function onTypeAreaKeyup(e, is_input) {
|
|
1673
1675
|
|
|
@@ -1683,15 +1685,20 @@ AlchemySelect.setMethod(function onTypeAreaKeyup(e, is_input) {
|
|
|
1683
1685
|
return;
|
|
1684
1686
|
}
|
|
1685
1687
|
|
|
1686
|
-
|
|
1688
|
+
let search_value = this.search_value,
|
|
1689
|
+
previous = this._previous_typed_search_value || '';
|
|
1687
1690
|
|
|
1691
|
+
if (previous != search_value) {
|
|
1688
1692
|
// Only perform a remote search
|
|
1689
1693
|
// when at least 2 characters have been entered
|
|
1690
|
-
if (
|
|
1694
|
+
if (search_value.length === 0 || search_value.length > 2) {
|
|
1691
1695
|
this.refreshRemote();
|
|
1692
1696
|
}
|
|
1697
|
+
|
|
1693
1698
|
}
|
|
1694
1699
|
|
|
1700
|
+
this._previous_typed_search_value = search_value;
|
|
1701
|
+
|
|
1695
1702
|
this.applyLocalFilter();
|
|
1696
1703
|
});
|
|
1697
1704
|
|
|
@@ -1700,7 +1707,7 @@ AlchemySelect.setMethod(function onTypeAreaKeyup(e, is_input) {
|
|
|
1700
1707
|
*
|
|
1701
1708
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
1702
1709
|
* @since 0.1.0
|
|
1703
|
-
* @version 0.
|
|
1710
|
+
* @version 0.2.3
|
|
1704
1711
|
*/
|
|
1705
1712
|
AlchemySelect.setMethod(function applyLocalFilter(query) {
|
|
1706
1713
|
|
|
@@ -1713,7 +1720,7 @@ AlchemySelect.setMethod(function applyLocalFilter(query) {
|
|
|
1713
1720
|
i;
|
|
1714
1721
|
|
|
1715
1722
|
if (query) {
|
|
1716
|
-
query = query.trim();
|
|
1723
|
+
query = query.trim().toLowerCase();
|
|
1717
1724
|
}
|
|
1718
1725
|
|
|
1719
1726
|
for (i = 0; i < this.dropdown_content.children.length; i++) {
|
|
@@ -1722,10 +1729,22 @@ AlchemySelect.setMethod(function applyLocalFilter(query) {
|
|
|
1722
1729
|
|
|
1723
1730
|
if (!query) {
|
|
1724
1731
|
allow = true;
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
if (!allow) {
|
|
1735
|
+
let value = String(element.value).toLowerCase();
|
|
1736
|
+
|
|
1737
|
+
if (value.includes(query)) {
|
|
1738
|
+
allow = true;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
if (!allow) {
|
|
1743
|
+
let text = element.textContent.toLowerCase();
|
|
1744
|
+
|
|
1745
|
+
if (text.includes(query)) {
|
|
1746
|
+
allow = true;
|
|
1747
|
+
}
|
|
1729
1748
|
}
|
|
1730
1749
|
|
|
1731
1750
|
if (allow) {
|
package/element/al_table.js
CHANGED
|
@@ -1121,7 +1121,7 @@ Table.setMethod(function getRemoteFetchConfig() {
|
|
|
1121
1121
|
*
|
|
1122
1122
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1123
1123
|
* @since 0.2.0
|
|
1124
|
-
* @version 0.2.
|
|
1124
|
+
* @version 0.2.3
|
|
1125
1125
|
*/
|
|
1126
1126
|
Table.setMethod(function applyFetchedData(err, result, config) {
|
|
1127
1127
|
|
|
@@ -1142,8 +1142,7 @@ Table.setMethod(function applyFetchedData(err, result, config) {
|
|
|
1142
1142
|
this.updateAnchors();
|
|
1143
1143
|
|
|
1144
1144
|
if (Blast.isBrowser) {
|
|
1145
|
-
|
|
1146
|
-
history.pushState(null, document.title, current_url+'');
|
|
1145
|
+
hawkejs.scene.pushToHistory(null, this.getCurrentStateUrl());
|
|
1147
1146
|
}
|
|
1148
1147
|
});
|
|
1149
1148
|
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alchemy-form",
|
|
3
3
|
"description": "Form plugin for Alchemy",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type" : "git",
|
|
7
7
|
"url" : "https://github.com/11ways/alchemy-form.git"
|
|
8
8
|
},
|
|
9
9
|
"peerDependencies": {
|
|
10
10
|
"alchemymvc" : ">=1.2.0",
|
|
11
|
-
"alchemy-media" : "
|
|
11
|
+
"alchemy-media" : ">=0.7.2"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"engines": {
|