Matrix Version:
5.3.2.1
Business problem:
The user is able to select a checkbox, which is a metadata field, on all PDF documents through Edit plus. We wanted to then make sure that the checkbox cannot be “unchecked”.
My solution:
I wrote some JS which checks for the checkbox element in the DOM (needed to poll every second, because it is not always in the DOM). Code below:
function waitForElementToExist(selector, time) {
if(document.querySelector(selector) != null) {
var cb = document.querySelector(selector);
//if "website" checkbox is checked, then disable it so it can't be changed
if(cb.checked) {
cb.disabled = true;
}
}
setTimeout(function() {
waitForElementToExist(selector, time);
}, time);
}
/** only do this if using edit+ on the intranet **/
if (window.location.href.indexOf("intranet") != -1) {
//ask this function to watch for when this element appears in the DOM
waitForElementToExist("#metadata_field_select_225992_Website", 1000);
}
Issue I need to solve now:
The very first time the user checks this box, the code sees this value change and disables the element, as it should.
But when the user goes to save it, it does not save the element with the “checked” value. After the document has saved, the checkbox reverts to “unchecked” and enabled (original state).
I’m guessing that the reason for this is that the field is disabled at the point of saving? Is there anything I can do to solve this problem?
Is there another way I can do this? I’ve looked into triggers, but couldn’t see anything there. Seemed that JS was the only way to do it.
TIA
Michael