Enable/disable submit button in submit a request page
Posted Apr 06, 2022
Hi,
I'm customizing "submit a request" page to disable "submit" button if subject and description are empty. I added some code to the subject input box to check content in both fields (subject and description) and if there is, enable "submit". This works fine.
When I add some code to "description", it doesn't work... the on change event for the textarea is never fired. Example:
var requestCommentTextarea = document.querySelector('.request_description textarea');requestCommentTextarea.addEventListener('change', function (event) {console.log(event.target.value);});
var requestCommentTextarea = document.querySelector('.request_description textarea');
var usesWysiwyg = requestCommentTextarea && requestCommentTextarea.dataset.helper === "wysiwyg";function isEmptyPlaintext(s) {
return s.trim() === '';
}function isEmptyHtml(xml) {
var doc = new DOMParser().parseFromString(`<_>${xml}</_>`, "text/xml");
var img = doc.querySelector("img");
return img === null && isEmptyPlaintext(doc.children[0].textContent);
}var isEmpty = usesWysiwyg ? isEmptyHtml : isEmptyPlaintext;
if (requestCommentTextarea) {
requestCommentTextarea.addEventListener('input', function () {
console.log("event");
if (isEmpty(requestCommentTextarea.value)) {
requestSubmitButton.disabled = true;
} else {
requestSubmitButton.disabled = false;
}
});
}
0
0 comments
Sign in to leave a comment.