Merge branch 'MDL-82788-404' of https://github.com/meirzamoodle/moodle into MOODLE_404_STABLE

This commit is contained in:
sarjona 2025-01-07 14:15:02 +01:00
commit 266b18f42f
3 changed files with 13 additions and 5 deletions

View File

@ -6,6 +6,6 @@
* @copyright 2016 Damyon Wiese <damyon@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("theme_boost/form-display-errors",["jquery","core_form/events"],(function($,FormEvent){let focusedAlready=!1;return{enhance:function(elementid){var element=document.getElementById(elementid);if(element){element.addEventListener(FormEvent.eventTypes.formFieldValidationFailed,(e=>{const msg=e.detail.message;e.preventDefault();var parent=$(element).closest(".fitem"),feedback=parent.find(".form-control-feedback");const feedbackId=feedback.attr("id");let describedBy=$(element).attr("aria-describedby");void 0===describedBy&&(describedBy="");let describedByIds=[];describedBy.length&&(describedByIds=describedBy.split(" "));const feedbackIndex=describedByIds.indexOf(feedbackId);"TEXTAREA"==$(element).prop("tagName")&&parent.find("[contenteditable]").length>0&&(element=parent.find("[contenteditable]")),""!==msg?(parent.addClass("has-danger"),parent.data("client-validation-error",!0),$(element).addClass("is-invalid"),-1===feedbackIndex&&(describedByIds.push(feedbackId),$(element).attr("aria-describedby",describedByIds.join(" "))),$(element).attr("aria-invalid",!0),feedback.html(msg),feedback.show(),focusedAlready||(element.scrollIntoView({behavior:"smooth",block:"center"}),focusedAlready=!0,setTimeout((()=>{element.focus({preventScroll:!0}),focusedAlready=!1}),0))):!0===parent.data("client-validation-error")&&(parent.removeClass("has-danger"),parent.data("client-validation-error",!1),$(element).removeClass("is-invalid"),feedbackIndex>-1&&describedByIds.splice(feedbackIndex,1),describedByIds.length?(describedBy=describedByIds.join(" "),$(element).attr("aria-describedby",describedBy)):$(element).removeAttr("aria-describedby"),$(element).attr("aria-invalid",!1),feedback.hide())}));var form=element.closest("form");form&&!("boostFormErrorsEnhanced"in form.dataset)&&(form.addEventListener("submit",(function(){var visibleError=$(".form-control-feedback:visible");visibleError.length&&visibleError[0].focus()})),form.dataset.boostFormErrorsEnhanced=1)}}}}));
define("theme_boost/form-display-errors",["jquery","core_form/events"],(function($,FormEvent){let focusedAlready=!1;return{enhance:function(elementid){var element=document.getElementById(elementid);if(element){element.addEventListener(FormEvent.eventTypes.formFieldValidationFailed,(e=>{const msg=e.detail.message;e.preventDefault();var parent=$(element).closest(".fitem"),feedback=parent.find(".form-control-feedback");const feedbackId=feedback.attr("id");let describedBy=$(element).attr("aria-describedby");void 0===describedBy&&(describedBy="");let describedByIds=[];describedBy.length&&(describedByIds=describedBy.split(" "));const feedbackIndex=describedByIds.indexOf(feedbackId);if("TEXTAREA"===element.tagName){const contentEditable=parent.find("[contenteditable]");element=contentEditable.length>0?contentEditable[0]:document.getElementById("".concat(element.id,"_ifr"))||element}""!==msg?(parent.addClass("has-danger"),parent.data("client-validation-error",!0),$(element).addClass("is-invalid"),-1===feedbackIndex&&(describedByIds.push(feedbackId),$(element).attr("aria-describedby",describedByIds.join(" "))),$(element).attr("aria-invalid",!0),feedback.html(msg),feedback.show(),focusedAlready||(element.scrollIntoView({behavior:"smooth",block:"center"}),focusedAlready=!0,setTimeout((()=>{element.focus({preventScroll:!0}),focusedAlready=!1}),0))):!0===parent.data("client-validation-error")&&(parent.removeClass("has-danger"),parent.data("client-validation-error",!1),$(element).removeClass("is-invalid"),feedbackIndex>-1&&describedByIds.splice(feedbackIndex,1),describedByIds.length?(describedBy=describedByIds.join(" "),$(element).attr("aria-describedby",describedBy)):$(element).removeAttr("aria-describedby"),$(element).attr("aria-invalid",!1),feedback.hide())}));var form=element.closest("form");form&&!("boostFormErrorsEnhanced"in form.dataset)&&(form.addEventListener("submit",(function(){var visibleError=$(".form-control-feedback:visible");visibleError.length&&visibleError[0].focus()})),form.dataset.boostFormErrorsEnhanced=1)}}}}));
//# sourceMappingURL=form-display-errors.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -60,10 +60,18 @@ define(['jquery', 'core_form/events'], function($, FormEvent) {
// Find the the feedback container in the aria-describedby attribute.
const feedbackIndex = describedByIds.indexOf(feedbackId);
// Sometimes (atto) we have a hidden textarea backed by a real contenteditable div.
if (($(element).prop("tagName") == 'TEXTAREA') && parent.find('[contenteditable]').length > 0) {
element = parent.find('[contenteditable]');
if (element.tagName === 'TEXTAREA') {
// Check if the textarea is backed by a contenteditable div.
const contentEditable = parent.find('[contenteditable]');
if (contentEditable.length > 0) {
// Use the contenteditable div as the target element.
element = contentEditable[0];
} else {
// Use the TinyMCE iframe as the target element if it exists.
element = document.getElementById(`${element.id}_ifr`) || element;
}
}
if (msg !== '') {
parent.addClass('has-danger');
parent.data('client-validation-error', true);