Hello,
I'm making another custom element and I have certain buttons in the creation form that I would like to be hidden unless the field "idMailable" has a certain value.
I can't do that with the screenCustomization plugin since it only handles type, status and profile conditions. Is there a specific function that is called when a field is changed and if so, how can I hide/show buttons without refreshing the page ?
I hope someone can help me
What you try and do is not possible.
You would need to change the core code.
Even if this is a new custom class ?
I was thinking about using the validation script to do something when the field changes, but I'm not sure what is the best way to hide field with js, but I think I've got something that could work.
In the onChange script of the idMailable field, I added this
function hideButton(id) {
dojo.byId(id).parentNode.parentNode.parentNode.style.display="none";
}
function showButton(id) {
dojo.byId(id).parentNode.parentNode.parentNode.style.display="";
}
dojo.xhrGet({
url : "../tool/telegramDisplayTemplateVisibleButtons.php?idMailable=" + dijit.byId("idMailable").get("value"),
handleAs : "json",
load : function(buttons) {
buttons["hidden"].forEach(but => hideButton(but));
buttons["visible"].forEach(but => showButton(but));
},
error : function() {}
});
And if I also call this part of the script when the field loads, it should work just fine
Okay so it works. The problem left is how to run the script when the field loads. I tried using the
but it doesn't work (it's not triggered). I'm not an expert with dojo so I don't know how to run some js when an element is loaded
I got it to work. I just set the hidden fields' attributes to "invisible" and the script now looks like this:
function hideButton(id) {
dojo.byId(id).parentNode.parentNode.parentNode.style.display="none";
dojo.byId(id).parentNode.style.display="none";
dojo.byId(id).parentNode.parentNode.parentNode.firstChild.firstChild.style.display="none";
}
function showButton(id) {
dojo.byId(id).parentNode.parentNode.parentNode.style.display="";
dojo.byId(id).parentNode.style.display="";
dojo.byId(id).parentNode.parentNode.parentNode.firstChild.firstChild.style.display="";
}
dojo.xhrGet({
url : "../tool/telegramDisplayTemplateVisibleButtons.php?idMailable=" + dijit.byId("idMailable").get("value"),
handleAs : "json",
load : function(buttons) {
buttons["hidden"].forEach(but => hideButton(but));
buttons["visible"].forEach(but => showButton(but));
},
error : function() {}
});
I think you should have used the existing hideWidget() function
or showWidget(), or disableWidget() or enableWidget()