最近搜索
没有最近搜索

Carlo Ligthart
已加入2021年4月16日
·
最后活动2021年10月29日
关注
0
关注者
0
活动总数
5
投票
0
订阅
1
活动概览
标记
文章
帖子
社区评论
文章评论
活动概览
的最新活动 Carlo Ligthart
Carlo Ligthart 进行了评论,
Carlo Ligthart 进行了评论,
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 进行了评论,
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
评论