최근 검색


최근 검색 없음

Carlo Ligthart's Avatar

Carlo Ligthart

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

·

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

팔로잉

0

팔로워

0

총 활동 수

5

투표 수

0

가입 플랜

1

활동 개요

님의 최근 활동 Carlo Ligthart

Carlo Ligthart님이 에 댓글을 입력함

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

Hi @...

I'm found the problem. The code wasn't in the document ready function. Thank you for all the help. Making attachments mandatory will also help us a lot!

Kind regards,
Carlo

댓글 보기 · 2020년 2월 20일에 게시됨 · Carlo Ligthart

0

팔로워

0

투표 수

0

댓글


Carlo Ligthart님이 에 댓글을 입력함

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

Hi @...

 

When I inspect  the checkbox I see the following:


I have the following set in the code:

var attachmentCheckboxField = 'request_custom_fields_360028787572';


 

Here is the full code if that might help:

// 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_360028787572';
var attachmentCheckboxId = '#' + attachmentCheckboxField;
var attachmentErrorNotification = 'Report must be attached';
var formDropdownClass = '.request_custom_fields_360028850151';
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() === 'ABCD';
}

// 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');

//Logging on request of Karen D Snyder
console.log('attachmentErrorElt.length: ' + attachmentErrorElt.length);
console.log('attachmentErrorNotification: ' + attachmentErrorNotification);

if (attachmentErrorElt.length) {
attachmentErrorElt.text(attachmentErrorNotification);
}

댓글 보기 · 2020년 2월 20일에 게시됨 · Carlo Ligthart

0

팔로워

0

투표 수

0

댓글


Carlo Ligthart님이 에 댓글을 입력함

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

Hi @...

Thank you for your quick reply.

I did what you suggested and I get a different output:

However, this results in 1:



댓글 보기 · 2020년 2월 20일에 게시됨 · Carlo Ligthart

0

팔로워

0

투표 수

0

댓글


Carlo Ligthart님이 에 댓글을 입력함

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

Hi @...

First of all: Thank you for this article!

I encounter the same problem as Fikri Akbar Hedianto ("Attachment: cannot be blank" message). I followed your steps exactly in the console and it indeed changed to: "Hello!" 

Any advice?

 

댓글 보기 · 2020년 2월 20일에 게시됨 · Carlo Ligthart

0

팔로워

0

투표 수

0

댓글