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

Prochaines Sessions

Les prochaines formations et démonstrations sont ouvertes, inscrivez-vous rapidement !

 

Démonstration de ProjeQtOr

(gratuit, sur inscription)
 

13 mai 2025 (10h30-12h)

5 juin 2025 (16h-17h30)

 
 

Planifiez avec ProjeQtOr

14 et 15 mai 2025 (9h-12h30)

18 et 19 juin 2025 (9h-12h30)

 
 

Administrez avec ProjeQtOr

20 et 21 mai (9h-12h30)

25 et 26 juin (9h-12h30)

 

 

 

Hide field depending on another field's value

More
22 Jui 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 Connexion or Create an account to join the conversation.

More
22 Jui 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 Connexion or Create an account to join the conversation.

More
22 Jui 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 Connexion or Create an account to join the conversation.

More
22 Jui 2021 14:09 - 22 Jui 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 Jui 2021 14:10 by Baryhobal.

Please Connexion or Create an account to join the conversation.

More
22 Jui 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 Connexion or Create an account to join the conversation.

More
24 Jui 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 Connexion or Create an account to join the conversation.

Moderators: babynusprotion
Time to create page: 0.038 seconds

Paramétrages de cookies

×

Cookies fonctionnels

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

Veuillez vous connecter pour voir vos activités!

Autres cookies

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