Forum

Welcome to ProjeQtOr new Forum. We migrated old forum to the new website.
You will find all your posts here, with your usual account.
Just one point : you’ll have to reinitialize your password. Use “Lost password” feature.

Hide field dependin...
 
Notifications
Clear all

Hide field depending on another field's value

6 Posts
2 Users
0 Reactions
1,389 Views
Louis Heredero
(@baryhobal)
Posts: 49
Active Member
Topic starter
 
[#7593]

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


 
Posted : 22 Jun 2021 2H14
babynus
(@babynus)
Posts: 14966
Main Contributor Admin
 

What you try and do is not possible.
You would need to change the core code.


 
Posted : 22 Jun 2021 13H00
Louis Heredero
(@baryhobal)
Posts: 49
Active Member
Topic starter
 

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


 
Posted : 22 Jun 2021 15H34
Louis Heredero
(@baryhobal)
Posts: 49
Active Member
Topic starter
 

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


 
Posted : 22 Jun 2021 16H09
Louis Heredero
(@baryhobal)
Posts: 49
Active Member
Topic starter
 

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() {}
});

 
Posted : 22 Jun 2021 16H57
babynus
(@babynus)
Posts: 14966
Main Contributor Admin
 

I think you should have used the existing hideWidget() function
or showWidget(), or disableWidget() or enableWidget()


 
Posted : 24 Jun 2021 14H49
Share:

Scroll to Top