Skip to content

Commit 578ac10

Browse files
committed
IBX-9976: Fixed styles for invalid fields labels
1 parent 55f013d commit 578ac10

File tree

13 files changed

+48
-18
lines changed

13 files changed

+48
-18
lines changed

src/bundle/Resources/public/js/scripts/fieldType/ezbinaryfile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,23 @@
3535
eventName: 'change',
3636
callback: 'validateInput',
3737
errorNodeSelectors: ['.ibexa-form-error'],
38+
invalidStateSelectors: ['.ibexa-field-edit__label'],
3839
},
3940
{
4041
isValueValidator: false,
4142
selector: `input[type="file"]`,
4243
eventName: 'ibexa-invalid-file-size',
4344
callback: 'showFileSizeError',
4445
errorNodeSelectors: ['.ibexa-form-error'],
46+
invalidStateSelectors: ['.ibexa-field-edit__label'],
4547
},
4648
{
4749
isValueValidator: false,
4850
selector: `input[type="file"]`,
4951
eventName: 'ibexa-invalid-file-type',
5052
callback: 'showFileTypeError',
5153
errorNodeSelectors: ['.ibexa-form-error'],
54+
invalidStateSelectors: ['.ibexa-field-edit__label'],
5255
},
5356
],
5457
});

src/bundle/Resources/public/js/scripts/fieldType/ezboolean.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(function (global, doc, ibexa) {
22
const SELECTOR_FIELD = '.ibexa-field-edit--ezboolean';
33
const SELECTOR_ERROR_NODE = '.ibexa-form-error';
4+
const SELECTOR_LABEL = '.ibexa-field-edit__label';
45

56
class EzBooleanValidator extends ibexa.BaseFieldValidator {
67
/**
@@ -13,7 +14,7 @@
1314
*/
1415
validateInput(event) {
1516
const isError = !event.target.checked && event.target.required;
16-
const label = event.target.closest(SELECTOR_FIELD).querySelector('.ibexa-field-edit__label').innerHTML;
17+
const label = event.target.closest(SELECTOR_FIELD).querySelector(SELECTOR_LABEL).innerText;
1718
const errorMessage = ibexa.errors.emptyField.replace('{fieldName}', label);
1819

1920
return {
@@ -32,6 +33,7 @@
3233
eventName: 'change',
3334
callback: 'validateInput',
3435
errorNodeSelectors: [SELECTOR_ERROR_NODE],
36+
invalidStateSelectors: [SELECTOR_LABEL],
3537
},
3638
],
3739
});

src/bundle/Resources/public/js/scripts/fieldType/ezemail.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(function (global, doc, ibexa) {
22
const SELECTOR_FIELD = '.ibexa-field-edit--ezemail';
33
const SELECTOR_ERROR_NODE = '.ibexa-form-error';
4+
const SELECTOR_LABEL = '.ibexa-field-edit__label';
45

56
class EzEmailValidator extends ibexa.BaseFieldValidator {
67
/**
@@ -17,7 +18,7 @@
1718
const isEmpty = !input.value.trim();
1819
const isValid = ibexa.errors.emailRegexp.test(input.value);
1920
const isError = (isRequired && isEmpty) || (!isEmpty && !isValid);
20-
const label = input.closest(SELECTOR_FIELD).querySelector('.ibexa-field-edit__label').innerHTML;
21+
const label = input.closest(SELECTOR_FIELD).querySelector(SELECTOR_LABEL).innerText;
2122
const result = { isError };
2223

2324
if (isRequired && isEmpty) {
@@ -39,6 +40,7 @@
3940
eventName: 'blur',
4041
callback: 'validateInput',
4142
errorNodeSelectors: [SELECTOR_ERROR_NODE],
43+
invalidStateSelectors: [SELECTOR_LABEL],
4244
},
4345
],
4446
});

src/bundle/Resources/public/js/scripts/fieldType/ezfloat.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(function (global, doc, ibexa) {
22
const SELECTOR_FIELD = '.ibexa-field-edit--ezfloat';
33
const SELECTOR_ERROR_NODE = `${SELECTOR_FIELD} .ibexa-form-error`;
4+
const SELECTOR_LABEL = '.ibexa-field-edit__label';
45

56
class EzFloatValidator extends ibexa.BaseFieldValidator {
67
/**
@@ -19,7 +20,7 @@
1920
const isLess = value < parseFloat(event.target.getAttribute('min'));
2021
const isGreater = value > parseFloat(event.target.getAttribute('max'));
2122
const isError = (isEmpty && isRequired) || (!isEmpty && (!isFloat || isLess || isGreater));
22-
const label = event.target.closest(SELECTOR_FIELD).querySelector('.ibexa-field-edit__label').innerHTML;
23+
const label = event.target.closest(SELECTOR_FIELD).querySelector(SELECTOR_LABEL).innerText;
2324
const result = { isError };
2425

2526
if (isEmpty) {
@@ -49,6 +50,7 @@
4950
eventName: 'blur',
5051
callback: 'validateFloat',
5152
errorNodeSelectors: [SELECTOR_ERROR_NODE],
53+
invalidStateSelectors: [SELECTOR_LABEL],
5254
},
5355
],
5456
});

src/bundle/Resources/public/js/scripts/fieldType/ezimage.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
const alreadyIsError = this.fieldContainer.classList.contains(this.classInvalid);
9696
const isEmpty = !event.target.value;
9797
const isError = alreadyIsError || (isEmpty && isRequired && !isFileFieldEmpty);
98-
const label = event.target.closest(SELECTOR_ALT_WRAPPER).querySelector('.ibexa-data-source__label').innerHTML;
98+
const label = event.target.closest(SELECTOR_ALT_WRAPPER).querySelector('.ibexa-data-source__label').innerText;
9999
const result = { isError };
100100

101101
if (isEmpty) {
@@ -116,12 +116,13 @@
116116
eventName: 'change',
117117
callback: 'validateInput',
118118
errorNodeSelectors: ['.ibexa-form-error'],
119+
invalidStateSelectors: ['.ibexa-field-edit__label'],
119120
},
120121
{
121122
selector: SELECTOR_INPUT_ALT,
122123
eventName: 'blur',
123124
callback: 'validateAltInput',
124-
invalidStateSelectors: ['.ibexa-data-source__field--alternativeText'],
125+
invalidStateSelectors: ['.ibexa-data-source__field--alternativeText', '.ibexa-field-edit__label'],
125126
errorNodeSelectors: [`${SELECTOR_ALT_WRAPPER} .ibexa-form-error`],
126127
},
127128
{
@@ -130,20 +131,22 @@
130131
eventName: 'ibexa-invalid-file-size',
131132
callback: 'showFileSizeError',
132133
errorNodeSelectors: ['.ibexa-form-error'],
134+
invalidStateSelectors: ['.ibexa-field-edit__label'],
133135
},
134136
{
135137
isValueValidator: false,
136138
selector: `${SELECTOR_INPUT_FILE}`,
137139
eventName: 'ibexa-invalid-file-type',
138140
callback: 'showFileTypeError',
139141
errorNodeSelectors: ['.ibexa-form-error'],
142+
invalidStateSelectors: ['.ibexa-field-edit__label'],
140143
},
141144
{
142145
isValueValidator: false,
143146
selector: SELECTOR_INPUT_ALT,
144147
eventName: EVENT_CANCEL_ERROR,
145148
callback: 'cancelErrors',
146-
invalidStateSelectors: ['.ibexa-data-source__field--alternativeText'],
149+
invalidStateSelectors: ['.ibexa-data-source__field--alternativeText', '.ibexa-field-edit__label'],
147150
errorNodeSelectors: [`${SELECTOR_ALT_WRAPPER} .ibexa-form-error`],
148151
},
149152
],

src/bundle/Resources/public/js/scripts/fieldType/ezimageasset.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,23 @@
254254
eventName: 'change',
255255
callback: 'validateInput',
256256
errorNodeSelectors: ['.ibexa-form-error'],
257+
invalidStateSelectors: ['.ibexa-field-edit__label'],
257258
},
258259
{
259260
isValueValidator: false,
260261
selector: `${SELECTOR_INPUT_FILE}`,
261262
eventName: 'ibexa-invalid-file-size',
262263
callback: 'showFileSizeError',
263264
errorNodeSelectors: ['.ibexa-form-error'],
265+
invalidStateSelectors: ['.ibexa-field-edit__label'],
264266
},
265267
{
266268
isValueValidator: false,
267269
selector: `${SELECTOR_INPUT_FILE}`,
268270
eventName: 'ibexa-invalid-file-type',
269271
callback: 'showFileTypeError',
270272
errorNodeSelectors: ['.ibexa-form-error'],
273+
invalidStateSelectors: ['.ibexa-field-edit__label'],
271274
},
272275
],
273276
});

src/bundle/Resources/public/js/scripts/fieldType/ezkeyword.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const SELECTOR_FIELD = '.ibexa-field-edit--ezkeyword';
33
const SELECTOR_TAGGIFY_CONTAINER = '.ibexa-data-source__taggify';
44
const SELECTOR_TAGGIFY = '.ibexa-data-source__taggify .ibexa-taggify';
5+
const SELECTOR_LABEL = '.ibexa-field-edit__label';
56
const SELECTOR_ERROR_NODE = '.ibexa-form-error';
67

78
class EzKeywordValidator extends ibexa.BaseFieldValidator {
@@ -16,7 +17,7 @@
1617
validateKeywords(event) {
1718
const fieldContainer = event.currentTarget.closest(SELECTOR_FIELD);
1819
const input = fieldContainer.querySelector('.ibexa-data-source__input-wrapper .ibexa-data-source__input');
19-
const label = fieldContainer.querySelector('.ibexa-field-edit__label').innerHTML;
20+
const label = fieldContainer.querySelector(SELECTOR_LABEL).innerText;
2021
const isRequired = input.required;
2122
const isEmpty = !input.value.trim().length;
2223
const isError = isEmpty && isRequired;
@@ -57,14 +58,14 @@
5758
eventName: 'blur',
5859
callback: 'validateKeywords',
5960
errorNodeSelectors: [SELECTOR_ERROR_NODE],
60-
invalidStateSelectors: [SELECTOR_TAGGIFY],
61+
invalidStateSelectors: [SELECTOR_TAGGIFY, SELECTOR_LABEL],
6162
},
6263
{
6364
selector: `${SELECTOR_FIELD} .ibexa-data-source__input.form-control`,
6465
eventName: 'change',
6566
callback: 'validateKeywords',
6667
errorNodeSelectors: [SELECTOR_ERROR_NODE],
67-
invalidStateSelectors: [SELECTOR_TAGGIFY],
68+
invalidStateSelectors: [SELECTOR_TAGGIFY, SELECTOR_LABEL],
6869
},
6970
],
7071
});
@@ -86,7 +87,7 @@
8687
acceptKeys: ['Enter', ','],
8788
});
8889
const updateKeywords = updateValue.bind(this, keywordInput);
89-
const taggifyInput = taggifyContainer.querySelector('.taggify__input');
90+
const taggifyInput = taggifyContainer.querySelector('.ibexa-taggify__input');
9091

9192
if (keywordInput.required) {
9293
taggifyInput.setAttribute('required', true);

src/bundle/Resources/public/js/scripts/fieldType/ezmedia.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const SELECTOR_INFO_WRAPPER = '.ibexa-field-edit-preview__info';
66
const SELECTOR_MEDIA_WRAPPER = '.ibexa-field-edit-preview__media-wrapper';
77
const SELECTOR_INPUT_FILE = 'input[type="file"]';
8+
const SELECTOR_LABEL = '.ibexa-field-edit__label-wrapper .ibexa-field-edit__label';
89
const CLASS_MEDIA_WRAPPER_LOADING = 'ibexa-field-edit-preview__media-wrapper--loading';
910

1011
class EzMediaValidator extends ibexa.BaseFileFieldValidator {
@@ -23,7 +24,7 @@
2324
const isEmpty = isNaN(value);
2425
const isInteger = Number.isInteger(value);
2526
const isError = (isEmpty && isRequired) || (!isEmpty && !isInteger);
26-
const label = input.closest(SELECTOR_INFO_WRAPPER).querySelector('.ibexa-field-edit-preview__label').innerHTML;
27+
const label = input.closest(SELECTOR_INFO_WRAPPER).querySelector('.ibexa-field-edit-preview__label').innerText;
2728
const result = { isError };
2829

2930
if (isEmpty) {
@@ -133,32 +134,38 @@
133134
const validator = new EzMediaValidator({
134135
classInvalid: 'is-invalid',
135136
fieldContainer,
137+
fieldSelector: SELECTOR_FIELD,
138+
labelSelector: SELECTOR_LABEL,
136139
eventsMap: [
137140
{
138141
isValueValidator: false,
139142
selector: SELECTOR_INPUT_FILE,
140143
eventName: 'ibexa-invalid-file-size',
141144
callback: 'showFileSizeError',
142145
errorNodeSelectors: ['.ibexa-field-edit--ezmedia .ibexa-form-error'],
146+
invalidStateSelectors: [SELECTOR_LABEL],
143147
},
144148
{
145149
isValueValidator: false,
146150
selector: SELECTOR_INPUT_FILE,
147151
eventName: 'ibexa-invalid-file-type',
148152
callback: 'showFileTypeError',
149153
errorNodeSelectors: ['.ibexa-field-edit--ezmedia .ibexa-form-error'],
154+
invalidStateSelectors: [SELECTOR_LABEL],
150155
},
151156
{
152157
selector: '.ibexa-field-edit-preview__dimensions .form-control',
153158
eventName: 'blur',
154159
callback: 'validateDimensions',
155160
errorNodeSelectors: [`${SELECTOR_INFO_WRAPPER} .ibexa-form-error`],
161+
invalidStateSelectors: [SELECTOR_LABEL],
156162
},
157163
{
158164
selector: SELECTOR_INPUT_FILE,
159165
eventName: 'change',
160166
callback: 'validateInput',
161167
errorNodeSelectors: ['.ibexa-field-edit--ezmedia .ibexa-form-error'],
168+
invalidStateSelectors: [SELECTOR_LABEL],
162169
},
163170
],
164171
});

src/bundle/Resources/public/js/scripts/fieldType/ezobjectrelationlist.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
const SELECTOR_FIELD_MULTIPLE = '.ibexa-field-edit--ezobjectrelationlist';
77
const SELECTOR_FIELD_SINGLE = '.ibexa-field-edit--ezobjectrelation';
88
const SELECTOR_INPUT = '.ibexa-data-source__input';
9+
const SELECTOR_LABEL = '.ibexa-field-edit__label';
910
const SELECTOR_BTN_ADD = '.ibexa-relations__table-action--create';
1011
const SELECTOR_ROW = '.ibexa-relations__item';
1112
const EVENT_CUSTOM = 'validateInput';
@@ -24,7 +25,7 @@
2425
const isEmpty = !currentTarget.value.length;
2526
const hasCorrectValues = currentTarget.value.split(',').every((id) => !isNaN(parseInt(id, 10)));
2627
const fieldContainer = currentTarget.closest(SELECTOR_FIELD_MULTIPLE) || currentTarget.closest(SELECTOR_FIELD_SINGLE);
27-
const label = fieldContainer.querySelector('.ibexa-field-edit__label').innerHTML;
28+
const label = fieldContainer.querySelector(SELECTOR_LABEL).innerText;
2829
const result = { isError: false };
2930

3031
if (isRequired && isEmpty) {
@@ -48,13 +49,15 @@
4849
selector: SELECTOR_INPUT,
4950
eventName: 'blur',
5051
callback: 'validateInput',
52+
invalidStateSelectors: [SELECTOR_LABEL],
5153
errorNodeSelectors: ['.ibexa-form-error'],
5254
},
5355
{
5456
isValueValidator: false,
5557
selector: SELECTOR_INPUT,
5658
eventName: EVENT_CUSTOM,
5759
callback: 'validateInput',
60+
invalidStateSelectors: [SELECTOR_LABEL],
5861
errorNodeSelectors: ['.ibexa-form-error'],
5962
},
6063
],

src/bundle/Resources/public/js/scripts/fieldType/ezselection.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const SELECTOR_SELECTED = '.ibexa-dropdown__selection-info';
44
const SELECTOR_ERROR_NODE = '.ibexa-form-error';
55
const EVENT_VALUE_CHANGED = 'change';
6+
const SELECTOR_LABEL = '.ibexa-field-edit__label';
67

78
class EzSelectionValidator extends ibexa.BaseFieldValidator {
89
/**
@@ -18,7 +19,7 @@
1819
const hasSelectedOptions = !!fieldContainer.querySelector('.ibexa-data-source__input').value;
1920
const isRequired = fieldContainer.classList.contains('ibexa-field-edit--required');
2021
const isError = isRequired && !hasSelectedOptions;
21-
const label = fieldContainer.querySelector('.ibexa-field-edit__label').innerHTML;
22+
const label = fieldContainer.querySelector(SELECTOR_LABEL).innerText;
2223
const errorMessage = ibexa.errors.emptyField.replace('{fieldName}', label);
2324

2425
return {
@@ -37,7 +38,7 @@
3738
eventName: EVENT_VALUE_CHANGED,
3839
callback: 'validateInput',
3940
errorNodeSelectors: [SELECTOR_ERROR_NODE],
40-
invalidStateSelectors: [SELECTOR_SELECTED],
41+
invalidStateSelectors: [SELECTOR_SELECTED, SELECTOR_LABEL],
4142
},
4243
],
4344
});

0 commit comments

Comments
 (0)