Skip to content

Commit

Permalink
Fix image validation (adobe#2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorJamesLow committed Oct 31, 2023
1 parent 3524e33 commit b999047
Showing 1 changed file with 12 additions and 4 deletions.
Expand Up @@ -13,7 +13,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
(function($, Granite) {
(function($, Granite) {
"use strict";

var dialogContentSelector = ".cmp-image__editor";
Expand Down Expand Up @@ -46,6 +46,7 @@
var altTextFromPage;
var altTextFromDAM;
var altCheckboxSelector = "coral-checkbox[name='./altValueFromDAM']";
var altIsDecorativeSelector = 'coral-checkbox[name="./isDecorative"]';
var altInputSelector = "input[name='./alt']";
var altInputAlertIconSelector = "input[name='./alt'] + coral-icon[icon='alert']";
var assetTabSelector = "coral-tab[data-foundation-tracking-event*='asset']";
Expand All @@ -65,7 +66,7 @@
$dialogContent = $dialog.find(dialogContentSelector);
var dialogContent = $dialogContent.length > 0 ? $dialogContent[0] : undefined;
if (dialogContent) {
isDecorative = dialogContent.querySelector('coral-checkbox[name="./isDecorative"]');
isDecorative = dialogContent.querySelector(altIsDecorativeSelector);

if ($(pageAltCheckboxSelector).length === 1) {
// when the tuple is used in the page dialog to define the featured image
Expand Down Expand Up @@ -170,8 +171,15 @@
validate: function() {
var seededValue = $(altInputSelector).attr("data-seeded-value");
var isAltCheckboxChecked = $(altCheckboxSelector).attr("checked");
var isDecorative = $(altIsDecorativeSelector).attr('checked');
var assetWithoutDescriptionErrorMessage = "Error: Please provide an asset which has a description that can be used as alt text.";
if (isAltCheckboxChecked && !seededValue) {

// Validate the following:
// - the image is not decorative
// - alt is not inherited from the DAM
// - the alt value is empty.
// If all of these are true, return a validation error
if (!isDecorative && !isAltCheckboxChecked && !seededValue) {
return Granite.I18n.get(assetWithoutDescriptionErrorMessage);
}
}
Expand Down Expand Up @@ -531,7 +539,7 @@
}
}
}

176
if (mutation.attributeName === "disabled") {
if ($(altInputSelector).val()) {
if (alertIcon.length) {
Expand Down

0 comments on commit b999047

Please sign in to comment.