Skip to content

Commit cef365d

Browse files
authored
[4.0] Hide the clear button when no value is set in media field (#34620)
* Hide the clear button when no value is set in media field * Remove duplicate code
1 parent 3fba151 commit cef365d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

build/media_source/system/js/fields/joomla-field-media.w-c.es6.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
this.clearValue = this.clearValue.bind(this);
1515
this.modalClose = this.modalClose.bind(this);
1616
this.setValue = this.setValue.bind(this);
17-
this.updatePreview = this.updatePreview.bind(this);
17+
this.updateState = this.updateState.bind(this);
1818
}
1919

2020
static get observedAttributes() {
@@ -108,7 +108,7 @@
108108
this.buttonClearEl.addEventListener('click', this.clearValue);
109109
}
110110

111-
this.updatePreview();
111+
this.updateState();
112112
}
113113

114114
disconnectedCallback() {
@@ -151,7 +151,7 @@
151151

152152
setValue(value) {
153153
this.inputElement.value = value;
154-
this.updatePreview();
154+
this.updateState();
155155

156156
// trigger change event both on the input and on the custom element
157157
this.inputElement.dispatchEvent(new Event('change'));
@@ -165,7 +165,10 @@
165165
this.setValue('');
166166
}
167167

168-
updatePreview() {
168+
updateState() {
169+
// Hide the clear button when no value is set
170+
this.buttonClearEl.style.display = this.inputElement.value ? '' : 'none';
171+
169172
if (['true', 'static'].indexOf(this.preview) === -1 || this.preview === 'false' || !this.previewElement) {
170173
return;
171174
}

build/media_source/system/js/fields/joomla-image-select.w-c.es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
}
174174
}
175175
editor.value = `${Joomla.selectedMediaFile.url}#joomlaImage://${media.path.replace(':', '')}?width=${Joomla.selectedMediaFile.width}&height=${Joomla.selectedMediaFile.height}`;
176-
fieldClass.updatePreview();
176+
fieldClass.updateState();
177177
}
178178
}
179179
}

0 commit comments

Comments
 (0)