alchemy-form 0.1.8 → 0.1.9

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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.1.9 (2022-07-06)
2
+
3
+ * Allow supplying a custom `data-src` to `alchemy-field` elements
4
+ * Add `view` templates for File & Datetime fields
5
+ * Use the new `alchemy.getClientModel()` method in `alchemy-field` element
6
+ * Add `alchemy-password-input` element
7
+
1
8
  ## 0.1.8 (2022-06-29)
2
9
 
3
10
  * Move the `alchemy-select` pagination checker initializer to a static function
@@ -39,7 +39,7 @@ alchemy-select {
39
39
  align-items: center;
40
40
 
41
41
  input.type-area {
42
- height: 1.5rem;
42
+ height: 1.5rem !important;
43
43
  }
44
44
  }
45
45
 
@@ -34,6 +34,15 @@ Field.setStylesheetFile('form/alchemy_field');
34
34
  */
35
35
  Field.setStatic('use_new_renderer_scope', true);
36
36
 
37
+ /**
38
+ * The data source url/route to use
39
+ *
40
+ * @author Jelle De Loecker <jelle@elevenways.be>
41
+ * @since 0.1.9
42
+ * @version 0.1.9
43
+ */
44
+ Field.setAttribute('data-src');
45
+
37
46
  /**
38
47
  * The name of the field
39
48
  *
@@ -160,7 +169,7 @@ Field.enforceProperty(function config(new_value, old_value) {
160
169
  *
161
170
  * @author Jelle De Loecker <jelle@elevenways.be>
162
171
  * @since 0.1.0
163
- * @version 0.1.0
172
+ * @version 0.1.9
164
173
  */
165
174
  Field.enforceProperty(function schema(new_value, old_value) {
166
175
 
@@ -181,15 +190,10 @@ Field.enforceProperty(function schema(new_value, old_value) {
181
190
  let model_name = this.model;
182
191
 
183
192
  if (model_name) {
184
- // @TODO: Always get the Client-side model here
185
- let model = alchemy.getModel(model_name);
193
+ let model = alchemy.getClientModel(model_name);
186
194
 
187
195
  if (model) {
188
196
  new_value = model.schema;
189
-
190
- if (Blast.isNode) {
191
- new_value = JSON.clone(new_value, 'toHawkejs');
192
- }
193
197
  }
194
198
  }
195
199
  }
@@ -715,7 +719,7 @@ Field.setMethod(function retained() {
715
719
  *
716
720
  * @author Jelle De Loecker <jelle@elevenways.be>
717
721
  * @since 0.1.0
718
- * @version 0.1.6
722
+ * @version 0.1.9
719
723
  *
720
724
  * @param {Object} config
721
725
  * @param {HTMLElement} element
@@ -742,7 +746,7 @@ Field.setMethod(async function loadData(config, element) {
742
746
  }
743
747
  }
744
748
 
745
- return this.hawkejs_helpers.Alchemy.getResource({
749
+ let resource_options = {
746
750
  name : 'FormApi#related',
747
751
  post : true,
748
752
  body : {
@@ -751,7 +755,13 @@ Field.setMethod(async function loadData(config, element) {
751
755
  assoc_model : field.options.modelName,
752
756
  config : config,
753
757
  }
754
- });
758
+ };
759
+
760
+ if (this.data_src) {
761
+ resource_options.name = this.data_src;
762
+ }
763
+
764
+ return this.hawkejs_helpers.Alchemy.getResource(resource_options);
755
765
  }
756
766
 
757
767
  });
@@ -0,0 +1,141 @@
1
+ /**
2
+ * The number-input custom element
3
+ *
4
+ * @author Jelle De Loecker <jelle@elevenways.be>
5
+ * @since 0.1.9
6
+ * @version 0.1.9
7
+ */
8
+ const PasswordInput = Function.inherits('Alchemy.Element.Form.StringInput', 'PasswordInput');
9
+
10
+ /**
11
+ * The template to use for the content of this element
12
+ *
13
+ * @author Jelle De Loecker <jelle@elevenways.be>
14
+ * @since 0.1.9
15
+ * @version 0.1.9
16
+ */
17
+ PasswordInput.setTemplateFile('form/elements/password_input');
18
+
19
+ /**
20
+ * Reference to the repeat input element
21
+ *
22
+ * @author Jelle De Loecker <jelle@elevenways.be>
23
+ * @since 0.1.9
24
+ * @version 0.1.9
25
+ */
26
+ PasswordInput.addElementGetter('repeat_el', '.repeat-input');
27
+
28
+ /**
29
+ * Reference to the repeat label element
30
+ *
31
+ * @author Jelle De Loecker <jelle@elevenways.be>
32
+ * @since 0.1.9
33
+ * @version 0.1.9
34
+ */
35
+ PasswordInput.addElementGetter('repeat_label', '.repeat-input-label');
36
+
37
+ /**
38
+ * The value property
39
+ *
40
+ * @author Jelle De Loecker <jelle@elevenways.be>
41
+ * @since 0.1.9
42
+ * @version 0.1.9
43
+ */
44
+ PasswordInput.setProperty(function value() {
45
+
46
+ let val;
47
+
48
+ if (this.input_el) {
49
+ val = this.input_el.value;
50
+ }
51
+
52
+ if (!val) {
53
+ return undefined;
54
+ }
55
+
56
+ if (!this.valuesAreEqual()) {
57
+ return undefined;
58
+ }
59
+
60
+ return val;
61
+ });
62
+
63
+ /**
64
+ * Are both inputs the same?
65
+ *
66
+ * @author Jelle De Loecker <jelle@elevenways.be>
67
+ * @since 0.1.9
68
+ * @version 0.1.9
69
+ */
70
+ PasswordInput.setMethod(function valuesAreEqual() {
71
+
72
+ let first_value = this.input_el?.value,
73
+ repeat_value = this.repeat_el?.value;
74
+
75
+ return first_value == repeat_value;
76
+ });
77
+
78
+ /**
79
+ * Revalidate the value
80
+ *
81
+ * @author Jelle De Loecker <jelle@elevenways.be>
82
+ * @since 0.1.9
83
+ * @version 0.1.9
84
+ */
85
+ PasswordInput.setMethod(async function revalidate() {
86
+
87
+ let first_value = this.input_el?.value,
88
+ repeat_value = this.repeat_el.value;
89
+
90
+ if (first_value) {
91
+ this.repeat_label.hidden = false;
92
+ } else {
93
+ this.repeat_el.value = '';
94
+ this.repeat_label.hidden = true;
95
+ }
96
+
97
+ this.removeErrors();
98
+
99
+ if (!first_value && !repeat_value) {
100
+ return;
101
+ }
102
+
103
+ if (first_value != repeat_value) {
104
+ return this.addError(this.__('does-not-match'), true);
105
+ }
106
+
107
+ return revalidate.super.call(this);
108
+ });
109
+
110
+ /**
111
+ * Actions to perform when this element
112
+ * has been added to the DOM for the first time
113
+ *
114
+ * @author Jelle De Loecker <jelle@elevenways.be>
115
+ * @since 0.1.9
116
+ * @version 0.1.9
117
+ */
118
+ PasswordInput.setMethod(function introduced() {
119
+
120
+ const that = this;
121
+
122
+ introduced.super.call(this);
123
+
124
+ this.repeat_el.addEventListener('focus', function onFocus(e) {
125
+ that.inputbox_el.classList.add('focus');
126
+ });
127
+
128
+ this.repeat_el.addEventListener('blur', function onBlur(e) {
129
+ that.inputbox_el.classList.remove('focus');
130
+ });
131
+
132
+ this.repeat_el.addEventListener('keyup', Fn.throttle(function onKeyup(e) {
133
+ that.revalidate();
134
+ that.emit('changing');
135
+ }, {
136
+ minimum_wait : 350,
137
+ immediate : false,
138
+ reset_on_call : true
139
+ }));
140
+
141
+ });
@@ -73,7 +73,7 @@ AlchemyField.enforceProperty(function alchemy_form(new_value) {
73
73
  *
74
74
  * @author Jelle De Loecker <jelle@elevenways.be>
75
75
  * @since 0.1.0
76
- * @version 0.1.4
76
+ * @version 0.1.9
77
77
  */
78
78
  AlchemyField.setMethod(function populateWidget() {
79
79
 
@@ -101,6 +101,10 @@ AlchemyField.setMethod(function populateWidget() {
101
101
  field_el.widget_settings = config.widget_settings;
102
102
  }
103
103
 
104
+ if (config.data_src) {
105
+ field_el.data_src = config.data_src;
106
+ }
107
+
104
108
  this.element.append(field_el);
105
109
  });
106
110
 
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.1.8",
4
+ "version": "0.1.9",
5
5
  "repository": {
6
6
  "type" : "git",
7
7
  "url" : "https://github.com/11ways/alchemy-form.git"
@@ -11,6 +11,6 @@
11
11
  },
12
12
  "license": "MIT",
13
13
  "engines": {
14
- "node" : ">=12.0.0"
14
+ "node" : ">=14.0.0"
15
15
  }
16
16
  }
@@ -0,0 +1,36 @@
1
+ <label>
2
+ <div class="inputlabel">
3
+ <span class="label" data-he-slot="label"></span>
4
+ <span class="description" data-he-slot="description"></span>
5
+ <hr class="spacer">
6
+ </div>
7
+ <div class="inputbox">
8
+ <input
9
+ name=<% self.getAttribute('input-name') || 'name' %>
10
+ placeholder=<% self.getAttribute('placeholder') %>
11
+ minlength=<% self.getAttribute('min-length') %>
12
+ maxlength=<% self.getAttribute('max-length') %>
13
+ class="input"
14
+ value="<% self.getAttribute('value') || '' %>"
15
+ type="password"
16
+ >
17
+ <i class="icon cross"></i>
18
+ <i class="icon checkmark"></i>
19
+ </div>
20
+ </label>
21
+ <label class="repeat-input-label" hidden>
22
+ <div class="inputbox">
23
+ <input
24
+ placeholder=<% self.getAttribute('repeat-placeholder') %>
25
+ class="input repeat-input"
26
+ value="<% self.getAttribute('value') || '' %>"
27
+ minlength=<% self.getAttribute('min-length') %>
28
+ maxlength=<% self.getAttribute('max-length') %>
29
+ type="password"
30
+ >
31
+ <i class="icon cross"></i>
32
+ <i class="icon checkmark"></i>
33
+ </div>
34
+ <div class="errors"></div>
35
+ <div class="success"></div>
36
+ </label>
@@ -0,0 +1 @@
1
+ <% include('form/inputs/view_inline/datetime') %>
@@ -0,0 +1,4 @@
1
+ <time
2
+ class="alchemy-field-value"
3
+ datetime={% value.toISOString() %}
4
+ >{{ value.format('Y‑m‑d H:i') }}</time>
@@ -0,0 +1,6 @@
1
+ {% if value %}
2
+ <img
3
+ !Media={% value %}
4
+ +media-route="Media::thumb"
5
+ >
6
+ {% /if %}