saasufy-components 10.0.0 → 10.0.1

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/README.md CHANGED
@@ -458,6 +458,7 @@ This component is a simplified version of the `collection-adder-form` component
458
458
  - `autocorrect`: Can be set to `off` to disable auto-correction of input on mobile devices.
459
459
  - `show-field-errors`: If this attribute exists on the element, then granular error messages will be shown above each corresponding input element instead of a single form-level error message.
460
460
  - `trim-spaces`: If this attribute exists on the element, then leading and trailing spaces will be trimmed from each input element's value before submitting the form.
461
+ - `reset-status-on-submit`: If this attribute exists, then the current message and any field errors will be cleared as soon as the form is submitted, instead of when the outcome of the submit is known. By default, the previous status is kept on screen until the insert either succeeds or fails and is then replaced within a single frame; this avoids the form flickering (shrinking and then growing again) when the same error occurs on consecutive submits.
461
462
  - `consumers`: This allows you to connect this `collection-adder` to other elements on your page. It should be used in conjunction with the `provider-template` attribute. The `consumers` attribute takes a list of selectors with optional attributes to target in the format `element-selector:attribute-name`. For example `.my-input:value` will find all elements with a `my-input` class and update their `value` attributes with the output of the `collection-adder` component on submit. You can specify multiple selectors separated by commas such as `.my-input,my-div`; in this case, because attribute names are not specified, values will be injected into the `value` attribute (for input elements) or into the `innerHTML` property (for other kinds of elements). The default attribute/property depends on the element type.
462
463
  - `success-consumers`: Same as the `consumers` attribute but the target elements are only updated if insertion was a success.
463
464
  - `error-consumers`: Same as the `consumers` attribute but the target elements are only updated if insertion was a failure.
@@ -499,6 +500,7 @@ This component is similar to the `collection-adder` component except that it req
499
500
  - `show-field-errors`: If this attribute exists on the element, then granular error messages will be shown above each corresponding input element instead of a single form-level error message.
500
501
  - `trim-spaces`: If this attribute exists on the element, then leading and trailing spaces will be trimmed from each input element's value before submitting the form.
501
502
  - `auto-reset-hidden-inputs`: If this attribute exists, then `hidden` input elements which are inside the `collection-adder-form` will be cleared along with other input fields. By default, `hidden` input elements are not cleared when the form is reset.
503
+ - `reset-status-on-submit`: If this attribute exists, then the current message and any field errors will be cleared as soon as the form is submitted, instead of when the outcome of the submit is known. By default, the previous status is kept on screen until the insert either succeeds or fails and is then replaced within a single frame; this avoids the form flickering (shrinking and then growing again) when the same error occurs on consecutive submits.
502
504
  - `disable-submit-on-enter-key`: If this attribute exists, then the form will not submit when the enter key is pressed.
503
505
  - `greedy-refresh`: If this attribute exists, the component will refresh itself whenever an attribute is set, even if that attribute's value did not change.
504
506
  - `consumers`: This allows you to connect this `collection-adder-form` to other elements on your page. It should be used in conjunction with the `provider-template` attribute. The `consumers` attribute takes a list of selectors with optional attributes to target in the format `element-selector:attribute-name`. For example `.my-input:value` will find all elements with a `my-input` class and update their `value` attributes with the output of the `collection-adder-form` component on submit. You can specify multiple selectors separated by commas such as `.my-input,my-div`; in this case, because attribute names are not specified, values will be injected into the `value` attribute (for input elements) or into the `innerHTML` property (for other kinds of elements). The default attribute/property depends on the element type.
@@ -50,22 +50,15 @@ class CollectionAdderForm extends SocketConsumer {
50
50
  throw new Error('Collection adder form is not ready to be submitted');
51
51
  }
52
52
  let successMessage = this.getAttribute('success-message');
53
- let messageContainer = this.shadowRoot.querySelector('slot[name="message"]').assignedElements()[0];
53
+ let messageContainer;
54
54
 
55
- if (messageContainer) {
56
- messageContainer.classList.remove('success');
57
- messageContainer.classList.remove('error');
58
- messageContainer.textContent = '';
55
+ // By default, the previous status is only cleared once the outcome of the
56
+ // submit is known so that the status is replaced within a single frame; this
57
+ // avoids the form flickering when the same error occurs twice in a row.
58
+ if (this.hasAttribute('reset-status-on-submit')) {
59
+ this.clearStatus();
59
60
  }
60
61
 
61
- // Clear any existing field errors
62
- let existingFieldErrors = this.querySelectorAll('.collection-adder-field-error-container');
63
- existingFieldErrors.forEach(el => el.remove());
64
-
65
- // Clear error classes from all inputs
66
- let allInputs = this.querySelectorAll('input, textarea, select');
67
- allInputs.forEach(input => input.classList.remove('error'));
68
-
69
62
  let trimSpaces = this.hasAttribute('trim-spaces');
70
63
 
71
64
  let inputElements = this.getAllInputElements();
@@ -133,6 +126,9 @@ class CollectionAdderForm extends SocketConsumer {
133
126
  };
134
127
 
135
128
  let resourceId = await this.collection.create(newModelData);
129
+
130
+ this.clearStatus();
131
+
136
132
  let insertedModelData = {
137
133
  ...newModelData,
138
134
  id: resourceId
@@ -162,6 +158,8 @@ class CollectionAdderForm extends SocketConsumer {
162
158
  }
163
159
  }
164
160
  } catch (error) {
161
+ this.clearStatus();
162
+
165
163
  messageContainer = this.shadowRoot.querySelector('slot[name="message"]').assignedElements()[0];
166
164
  if (messageContainer) {
167
165
  messageContainer.classList.add('error');
@@ -229,6 +227,24 @@ class CollectionAdderForm extends SocketConsumer {
229
227
  updateConsumerElements.call(this, oppositeOutcomeConsumers, '', null, selfName);
230
228
  }
231
229
 
230
+ clearStatus() {
231
+ let messageContainer = this.shadowRoot.querySelector('slot[name="message"]').assignedElements()[0];
232
+
233
+ if (messageContainer) {
234
+ messageContainer.classList.remove('success');
235
+ messageContainer.classList.remove('error');
236
+ messageContainer.textContent = '';
237
+ }
238
+
239
+ // Clear any existing field errors
240
+ let existingFieldErrors = this.querySelectorAll('.collection-adder-field-error-container');
241
+ existingFieldErrors.forEach(el => el.remove());
242
+
243
+ // Clear error classes from all inputs
244
+ let allInputs = this.querySelectorAll('input, textarea, select');
245
+ allInputs.forEach(input => input.classList.remove('error'));
246
+ }
247
+
232
248
  getAllInputElements() {
233
249
  return this.shadowRoot.querySelector('.input-slot')
234
250
  .assignedElements()
@@ -55,17 +55,12 @@ class CollectionAdder extends SocketConsumer {
55
55
  let successMessage = this.getAttribute('success-message');
56
56
  let messageContainer = this.querySelector('.collection-adder-message-container');
57
57
 
58
- messageContainer.classList.remove('success');
59
- messageContainer.classList.remove('error');
60
- messageContainer.textContent = '';
61
-
62
- // Clear any existing field errors
63
- let existingFieldErrors = this.querySelectorAll('.collection-adder-field-error-container');
64
- existingFieldErrors.forEach(el => el.textContent = '');
65
-
66
- // Clear error classes from all inputs
67
- let allInputs = this.querySelectorAll('.collection-adder-input, .collection-adder-radio');
68
- allInputs.forEach(input => input.classList.remove('error'));
58
+ // By default, the previous status is only cleared once the outcome of the
59
+ // submit is known so that the status is replaced within a single frame; this
60
+ // avoids the form flickering when the same error occurs twice in a row.
61
+ if (this.hasAttribute('reset-status-on-submit')) {
62
+ this.clearStatus();
63
+ }
69
64
 
70
65
  let radioInputs = [ ...this.querySelectorAll('.collection-adder-radio') ];
71
66
  let radioData = {};
@@ -131,6 +126,9 @@ class CollectionAdder extends SocketConsumer {
131
126
  )
132
127
  };
133
128
  let resourceId = await this.collection.create(newModelData);
129
+
130
+ this.clearStatus();
131
+
134
132
  let insertedModelData = {
135
133
  ...newModelData,
136
134
  id: resourceId
@@ -156,6 +154,8 @@ class CollectionAdder extends SocketConsumer {
156
154
  messageContainer.textContent = '';
157
155
  }
158
156
  } catch (error) {
157
+ this.clearStatus();
158
+
159
159
  messageContainer.classList.add('error');
160
160
  messageContainer.classList.remove('success');
161
161
 
@@ -213,6 +213,24 @@ class CollectionAdder extends SocketConsumer {
213
213
  updateConsumerElements.call(this, oppositeOutcomeConsumers, '', null, selfName);
214
214
  }
215
215
 
216
+ clearStatus() {
217
+ let messageContainer = this.querySelector('.collection-adder-message-container');
218
+
219
+ if (messageContainer) {
220
+ messageContainer.classList.remove('success');
221
+ messageContainer.classList.remove('error');
222
+ messageContainer.textContent = '';
223
+ }
224
+
225
+ // Clear any existing field errors
226
+ let existingFieldErrors = this.querySelectorAll('.collection-adder-field-error-container');
227
+ existingFieldErrors.forEach(el => el.textContent = '');
228
+
229
+ // Clear error classes from all inputs
230
+ let allInputs = this.querySelectorAll('.collection-adder-input, .collection-adder-radio');
231
+ allInputs.forEach(input => input.classList.remove('error'));
232
+ }
233
+
216
234
  reset() {
217
235
  let form = this.querySelector('.collection-adder-form');
218
236
  if (form) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "10.0.0",
3
+ "version": "10.0.1",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {