Open HitmanInWis opened 4 weeks ago
This can be solved by adding a check to the validation message to see if the image is set.
Add an imageIsSet
function using the logic from the code that sets alt required/not:
function imageIsSet() {
return $("coral-fileupload.is-filled:not(:hidden)").length !== 0;
}
Refactor ths code that sets the alt field as required/not from:
$altTextField.adaptTo("foundation-field").setRequired(!isDecorativeCheckbox.checked && $("coral-fileupload.is-filled:not(:hidden)").length !== 0);
to:
$altTextField.adaptTo("foundation-field").setRequired(!isDecorativeCheckbox.checked && imageIsSet());
Refactor the alt field validation code from:
if (isAltCheckboxChecked && !seededValue && !isDecorativeChecked) {
return Granite.I18n.get(assetWithoutDescriptionErrorMessage);
}
to
if (imageIsSet() && isAltCheckboxChecked && !seededValue && !isDecorativeChecked) {
return Granite.I18n.get(assetWithoutDescriptionErrorMessage);
}
There's also a bug where the standard "required" check is preventing the dialog from closing for empty alt text after the selected image is cleared (though to be fair this is pretty edge case).
To fix this, update:
$cqFileUpload.on("click", "[coral-fileupload-clear]", function() {
altTuple.reset();
captionTuple.reset();
});
to
$cqFileUpload.on("click", "[coral-fileupload-clear]", function() {
toggleAlternativeFieldsAndLink(imageFromPageImage, isDecorative); // ADD THIS
altTuple.reset();
captionTuple.reset();
});
Bug present as of version: 2.24.7-SNAPSHOT
In either of the following cases, Alt text is required before I can close the dialog saving my changes:
Until an image is specified, the dialog should not require alt text to close, otherwise the author is forced to lose changes.