Problem saving value of a metadata field in Edit Plus


(Mahearnpad) #1

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


(Bart Banda) #2

That’s right.

This sounds like a weird requirement, but what you could do is maybe hide the checkbox field all together and put readonly attribute on it instead of disabled? Then you could also show some other text instead of the hidden checkbox field with the JS?


(Mahearnpad) #3

Great! That is the kind of lateral thinking I was hoping for from this forum (and you in particular). I’ll give it a try.

thanks


(Mahearnpad) #4

Great solution Bart!

For the record. A checkbox doesn’t have a ‘readonly’ attribute. But I was able to hide the actual element by using the style attribute (style.display = ‘none’).

All good now

thanks again!