-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VACMS-15785: alt text validation (#15787)
* VACMS-15435: hard validation for alt text field * VACMS-15436: clientside validation for alt text field * VACMS-15436: updated composer.lock * VACMS-15436: fix linting errors * VACMS-15436: one more linting error fixed * VACMS-15436: more linting fixes * VACMS-15785: updated composer.lock * VACMS-15962: theming changes for image form * VACMS-15962: fix linting errors * VACMS-15962: final fix * VACMS-15783: Alt-Text Validation Testing (#16159) * VACMS-15783 adds alt-text validation tests * VACMS-15785: update composer.lock, fix merge error * VACMS-15785: fix for spacing around error * VACMS-15785: updated composer.lock * Updates content * smdh --------- Co-authored-by: Tony Taylor <[email protected]> Co-authored-by: Nathan Douglas <[email protected]>
- Loading branch information
1 parent
8a12098
commit 91d2e1e
Showing
26 changed files
with
987 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
_core: | ||
default_config_hash: GfA9lmRURupNRAARLoOTo1Ihq1-M3ktT0sKSjUcL2sw | ||
enable_all_forms: true | ||
enabled_forms: { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
_core: | ||
default_config_hash: 3YUV4RQQ4k8drO7uzYJ7lNc5Az0iDAH5YW8KbZVxjeY | ||
use_cdn: false | ||
cdn_base_url: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/' | ||
validate_all_ajax_forms: 2 | ||
force_validate_on_blur: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,6 @@ | |
} | ||
|
||
.form-item--error-message { | ||
color: var(--va-red-bright); | ||
color: var(--va-red-dark); | ||
margin: 5px 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
docroot/modules/custom/va_gov_media/js/alt_text_validation.es6.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* @file | ||
* Attaches behaviors VA GOv Media module. | ||
*/ | ||
(($, Drupal, once, drupalSettings) => { | ||
if (typeof drupalSettings.cvJqueryValidateOptions === "undefined") { | ||
drupalSettings.cvJqueryValidateOptions = {}; | ||
} | ||
|
||
if (drupalSettings.clientside_validation_jquery.force_validate_on_blur) { | ||
drupalSettings.cvJqueryValidateOptions.onfocusout = (element) => { | ||
// "eager" validation | ||
this.element(element); | ||
}; | ||
} | ||
|
||
drupalSettings.cvJqueryValidateOptions.rules = { | ||
"image[0][alt]": { | ||
remote: { | ||
url: `${drupalSettings.path.baseUrl}media/validate`, | ||
type: "post", | ||
data: { | ||
value() { | ||
return $("textarea[data-drupal-selector='edit-image-0-alt']").val(); | ||
}, | ||
}, | ||
dataType: "json", | ||
}, | ||
}, | ||
"media[0][fields][image][0][alt]": { | ||
remote: { | ||
url: `${drupalSettings.path.baseUrl}media/validate`, | ||
type: "post", | ||
data: { | ||
value() { | ||
return $( | ||
"textarea[data-drupal-selector='edit-media-0-fields-image-0-alt']" | ||
).val(); | ||
}, | ||
}, | ||
dataType: "json", | ||
}, | ||
}, | ||
}; | ||
|
||
// Add messages with translations from backend. | ||
$.extend( | ||
$.validator.messages, | ||
drupalSettings.clientside_validation_jquery.messages | ||
); | ||
|
||
/** | ||
* Attaches jQuery validate behavior to forms. | ||
* | ||
* @type {Drupal~behavior} | ||
* | ||
* @prop {Drupal~behaviorAttach} attach | ||
* Attaches the outline behavior to the right context. | ||
*/ | ||
Drupal.behaviors.altTextValidate = { | ||
// eslint-disable-next-line no-unused-vars | ||
attach(context) { | ||
// Allow all modules to update the validate options. | ||
// Example of how to do this is shown below. | ||
$(document).trigger( | ||
"cv-jquery-validate-options-update", | ||
drupalSettings.cvJqueryValidateOptions | ||
); | ||
|
||
// Process for all the forms on the page everytime, | ||
// we already use once so we should be good. | ||
once("altTextValidate", "body form").forEach((element) => { | ||
$(element).validate(drupalSettings.cvJqueryValidateOptions); | ||
}); | ||
}, | ||
}; | ||
// eslint-disable-next-line no-undef | ||
})(jQuery, Drupal, once, drupalSettings); |
52 changes: 52 additions & 0 deletions
52
docroot/modules/custom/va_gov_media/js/alt_text_validation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* DO NOT EDIT THIS FILE. | ||
* See the following change record for more information, | ||
* https://www.drupal.org/node/2815083 | ||
* @preserve | ||
**/ | ||
var _this = this; | ||
(function ($, Drupal, once, drupalSettings) { | ||
if (typeof drupalSettings.cvJqueryValidateOptions === "undefined") { | ||
drupalSettings.cvJqueryValidateOptions = {}; | ||
} | ||
if (drupalSettings.clientside_validation_jquery.force_validate_on_blur) { | ||
drupalSettings.cvJqueryValidateOptions.onfocusout = function (element) { | ||
_this.element(element); | ||
}; | ||
} | ||
drupalSettings.cvJqueryValidateOptions.rules = { | ||
"image[0][alt]": { | ||
remote: { | ||
url: drupalSettings.path.baseUrl + "media/validate", | ||
type: "post", | ||
data: { | ||
value: function value() { | ||
return $("textarea[data-drupal-selector='edit-image-0-alt']").val(); | ||
} | ||
}, | ||
dataType: "json" | ||
} | ||
}, | ||
"media[0][fields][image][0][alt]": { | ||
remote: { | ||
url: drupalSettings.path.baseUrl + "media/validate", | ||
type: "post", | ||
data: { | ||
value: function value() { | ||
return $("textarea[data-drupal-selector='edit-media-0-fields-image-0-alt']").val(); | ||
} | ||
}, | ||
dataType: "json" | ||
} | ||
} | ||
}; | ||
$.extend($.validator.messages, drupalSettings.clientside_validation_jquery.messages); | ||
Drupal.behaviors.altTextValidate = { | ||
attach: function attach(context) { | ||
$(document).trigger("cv-jquery-validate-options-update", drupalSettings.cvJqueryValidateOptions); | ||
once("altTextValidate", "body form").forEach(function (element) { | ||
$(element).validate(drupalSettings.cvJqueryValidateOptions); | ||
}); | ||
} | ||
}; | ||
})(jQuery, Drupal, once, drupalSettings); |
Oops, something went wrong.