최근 검색


최근 검색 없음

Kevin Witt's Avatar

Kevin Witt

가입한 날짜: 2021년 4월 16일

·

마지막 활동: 2021년 10월 29일

팔로잉

0

팔로워

0

총 활동 수

11

투표 수

0

플랜 수

8

활동 개요

님의 최근 활동 Kevin Witt

Kevin Witt님이 에 댓글을 입력함

커뮤니티 댓글 Discussion - Tips and best practices from the community

A big thank-you to @..., you saved me allot of time with this.

 

댓글 보기 · 2019년 10월 21일에 게시됨 · Kevin Witt

0

팔로워

0

투표 수

0

댓글


Kevin Witt님이 에 댓글을 입력함

커뮤니티 댓글 Discussion - Tips and best practices from the community

Sure, a configured as per the article (Except I didn't hide the checkbox at this point so I can see what is happening).

I have a drop-down that determines if the attachment is required, with the options "Attachment not required" and "Attachment required".

The error I see in the console is:

The HC is in my sandbox: https://unifydemo1508140682.zendesk.com

The form is called "Attachment Test".

My JS is as follows:

// Callback function to execute when mutations in form attachments or dropdown are observed:
// clear or select Attachment checkbox according to dropdown
var mutationObservedForm = function (mutationsList) {
mutationsList.forEach(function (mutation) {
if (mutation.type == 'childList') {
setFormAttachmentCheckbox();
}
});
};

// Define some variables for requiring form attachments
var attachmentCheckboxField = 'request_custom_fields_360003651537';
var attachmentCheckboxId = '#' + attachmentCheckboxField;
var attachmentErrorNotification = 'Report must be attached';
var formDropdownClass = '.request_custom_fields_360003651357';
var formObserveMutationOptions = { childList: true, subtree: true };

// Clear or select checkbox according to dropdown and attachments:
// Set Attachment checkbox if no attachments required, or if attachments are required and at least one is uploaded, otherwise clear it
function setFormAttachmentCheckbox() {
if (isFormAttachmentRequired()) {
if ($('#request-attachments-pool .upload-item').length) {
selectCheckbox(attachmentCheckboxId);
}
else {
clearCheckbox(attachmentCheckboxId);
}
}
else {
selectCheckbox(attachmentCheckboxId);
}
}

// Return true if dropdown option 'ABCD' is selected
function isFormAttachmentRequired() {
return $(formDropdownClass + ' a.nesty-input').attr('aria-expanded') &&
$(formDropdownClass + ' a.nesty-input').text() === 'Attachment required';
}

// Select checkbox
function selectCheckbox(eltselector) {
$(eltselector).prop('checked', true);
}

// Clear checkbox
function clearCheckbox(eltselector) {
$(eltselector).prop('checked', false);
}

// If attachment checkbox field exists, select it,
// and watch for changes to attachments and dropdown
if ($(attachmentCheckboxId).length) {
selectCheckbox(attachmentCheckboxId);
startObserveMutations('#request-attachments-pool', formObserveMutationOptions, mutationObservedForm);
startObserveMutations(formDropdownClass, formObserveMutationOptions, mutationObservedForm);
}

// Adjust attachment error notification
var attachmentErrorElt = $('.' + attachmentCheckboxField + ' .notification-error');
if (attachmentErrorElt.length) {
attachmentErrorElt.text(attachmentErrorNotification);
}


댓글 보기 · 2019년 10월 17일에 게시됨 · Kevin Witt

0

팔로워

0

투표 수

0

댓글


Kevin Witt님이 에 댓글을 입력함

커뮤니티 댓글 Discussion - Tips and best practices from the community

Great article, but I am having problems with the js.  I get the following error in console "startObserveMutations is not defined".

Am I missing something?

댓글 보기 · 2019년 10월 17일에 게시됨 · Kevin Witt

0

팔로워

0

투표 수

0

댓글