View ProjeQtOr On SourceForge.net
ProjeQtOr - Project Management Tool
Support us on Capterra
OIN - Open Invention Network
ProjeQtOr free project management software - Hide field depending on another field's value - ProjeQtOr
 

Hide field depending on another field's value

More
22 Jun 2021 00:14 #1 by Baryhobal
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

Please Log in or Create an account to join the conversation.

More
22 Jun 2021 11:00 #2 by babynus
What you try and do is not possible.
You would need to change the core code.

Babynus
Administrator of ProjeQtOr web site

Please Log in or Create an account to join the conversation.

More
22 Jun 2021 13:34 #3 by Baryhobal
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

Please Log in or Create an account to join the conversation.

More
22 Jun 2021 14:09 - 22 Jun 2021 14:10 #4 by Baryhobal
Okay so it works. The problem left is how to run the script when the field loads. I tried using the
<script type="dojo/connect" event="onLoad" args="evt">
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
Last edit: 22 Jun 2021 14:10 by Baryhobal.

Please Log in or Create an account to join the conversation.

More
22 Jun 2021 14:57 #5 by Baryhobal
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() {}
});

Please Log in or Create an account to join the conversation.

More
24 Jun 2021 12:49 #6 by babynus
I think you should have used the existing hideWidget() function
or showWidget(), or disableWidget() or enableWidget()

Babynus
Administrator of ProjeQtOr web site

Please Log in or Create an account to join the conversation.

Moderators: babynusprotion
Time to create page: 0.044 seconds

Cookies settings

×

Functional Cookies

Ce site utilise des cookies pour assurer son bon fonctionnement et ne peuvent pas être désactivés de nos systèmes. Nous ne les utilisons pas à des fins publicitaires. Si ces cookies sont bloqués, certaines parties du site ne pourront pas fonctionner.

Session

Please login to see yours activities!

Other cookies

Ce site web utilise un certain nombre de cookies pour gérer, par exemple, les sessions utilisateurs.