alchemy-form 0.2.8 → 0.2.10

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.
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Recompute fields in the browser that has its logic in the server
3
+ *
4
+ * @author Jelle De Loecker <jelle@elevenways.be>
5
+ * @since 0.2.9
6
+ * @version 0.2.9
7
+ *
8
+ * @param {Alchemy.Client.Document} document
9
+ * @param {Alchemy.Client.Field} field
10
+ */
11
+ alchemy.registerCustomHandler('recompute_field', async function fieldRecomputeHandler(document, field) {
12
+
13
+ let body = {
14
+ _id : document._id,
15
+ };
16
+
17
+ for (let other_field of field.dependency_fields) {
18
+ let value = other_field.getRecordValue(document);
19
+ body[other_field.name] = value;
20
+ }
21
+
22
+ let resource_options = {
23
+ name : 'FormApi#recompute',
24
+ post : true,
25
+ body : body,
26
+ };
27
+
28
+ let params = {
29
+ model_name : document.$model_name,
30
+ field : field.name,
31
+ };
32
+
33
+ console.log(document)
34
+
35
+ let helpers;
36
+
37
+ if (Blast.isServer) {
38
+ helpers = document.conduit?.renderer?.helpers;
39
+ } else {
40
+ helpers = hawkejs.scene.helpers;
41
+ }
42
+
43
+ if (!helpers) {
44
+ return;
45
+ }
46
+
47
+ let response = await helpers.Alchemy.getResource(resource_options, params);
48
+
49
+ return response?.result;
50
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "alchemy-form",
3
3
  "description": "Form plugin for Alchemy",
4
- "version": "0.2.8",
4
+ "version": "0.2.10",
5
5
  "repository": {
6
6
  "type" : "git",
7
7
  "url" : "https://github.com/11ways/alchemy-form.git"
@@ -5,7 +5,7 @@ variables = {
5
5
  alchemy_field : self,
6
6
  field_context : self,
7
7
  view_files : view_files,
8
- value : self.original_value,
8
+ value : self.value_to_render,
9
9
  }
10
10
  %>
11
11
 
@@ -1,5 +1,7 @@
1
1
  <al-select
2
2
  class="alchemy-field-value"
3
+ value-item-template={% alchemy_field.getFieldOption('value_item_template') %}
4
+ option-item-template={% alchemy_field.getFieldOption('option_item_template') %}
3
5
  ><%
4
6
  $0.dataprovider = alchemy_field;
5
7
  $0.name = path;
@@ -0,0 +1,7 @@
1
+ <input
2
+ value=<% value %>
3
+ class="alchemy-field-value"
4
+ type="number"
5
+ form=<% form_id %>
6
+ name=<% path %>
7
+ >
@@ -0,0 +1,15 @@
1
+ <%
2
+ if (alchemy_field && alchemy_field.config && alchemy_field.config.options && alchemy_field.config.options.scale != null) {
3
+ step = 10 ** (-1 * alchemy_field.config.options.scale);
4
+ } else {
5
+ step = 1;
6
+ }
7
+ %>
8
+ <input
9
+ value=<% value %>
10
+ class="alchemy-field-value"
11
+ type="number"
12
+ form=<% form_id %>
13
+ name=<% path %>
14
+ step={% step %}
15
+ >
@@ -0,0 +1,7 @@
1
+ <input
2
+ value=<% value %>
3
+ class="alchemy-field-value"
4
+ type="hidden"
5
+ form=<% form_id %>
6
+ name=<% path %>
7
+ >
@@ -0,0 +1,8 @@
1
+ <input
2
+ value=<% value %>
3
+ class="alchemy-field-value"
4
+ type="number"
5
+ form=<% form_id %>
6
+ name=<% path %>
7
+ step="1"
8
+ >
@@ -0,0 +1,13 @@
1
+ <%
2
+ if (value) {
3
+ value = value.format('Y-m-d');
4
+ }
5
+ %>
6
+ <input
7
+ value=<% value %>
8
+ class="alchemy-field-value"
9
+ type="date"
10
+ form=<% form_id %>
11
+ name=<% path %>
12
+ pattern="\d{4}-\d{2}-\d{2}"
13
+ >
@@ -0,0 +1,20 @@
1
+ <%
2
+
3
+ if (value) {
4
+
5
+ // Make sure it's a date
6
+ value = LocalDate.create(value);
7
+
8
+ // According to MDN `toISOString()` should work,
9
+ // but neither Chrome or Firefox allow that format (it still contains timezone info)
10
+ value = value.format('Y-m-d\\TH:i:s');
11
+ }
12
+ %>
13
+ <input
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
+ >
@@ -0,0 +1,14 @@
1
+ <%
2
+ if (value) {
3
+ value = value.format('H:i:s');
4
+ }
5
+ %>
6
+ <input
7
+ value=<% value %>
8
+ class="alchemy-field-value"
9
+ type="time"
10
+ form=<% form_id %>
11
+ name=<% path %>
12
+ pattern="\d{2}:\d{2}:\d{2}"
13
+ step=1
14
+ >
@@ -0,0 +1,7 @@
1
+ <input
2
+ value=<% value %>
3
+ class="alchemy-field-value"
4
+ type="hidden"
5
+ form=<% form_id %>
6
+ name=<% path %>
7
+ >
@@ -0,0 +1,7 @@
1
+ <input
2
+ value=<% value %>
3
+ class="alchemy-field-value"
4
+ type="hidden"
5
+ form=<% form_id %>
6
+ name=<% path %>
7
+ >