Hide field depending on dropdown

Discussion forum about Anuko Time Tracker
Post Reply
Uashbjo
Posts: 13
Joined: Tue Oct 24, 2017 9:41 pm

Hide field depending on dropdown

Post by Uashbjo » Sun Nov 12, 2017 6:24 pm

Hi, does anybody have an idea how to make the custom field visible only if a specific option is selected in the dropdown menu?

Thank You!

Uashbjo
Posts: 13
Joined: Tue Oct 24, 2017 9:41 pm

Re: Hide field depending on dropdown

Post by Uashbjo » Tue Nov 21, 2017 7:34 pm

Finally found a way to do it with trial and error.

Roboroadie
Posts: 3
Joined: Sun Jan 14, 2018 7:29 pm

Re: Hide field depending on dropdown

Post by Roboroadie » Sun Jan 14, 2018 7:33 pm

any chance you could share how you accomplished this ? I have been trying with no luck

wrc
Posts: 251
Joined: Tue May 25, 2010 8:30 pm

Re: Hide field depending on dropdown

Post by wrc » Mon Jan 15, 2018 12:26 am

You mean hiding the custom field control depending in project or task selection? You'll need some JavaScript for this. Can you explain the need for this for the rest of us?

Roboroadie
Posts: 3
Joined: Sun Jan 14, 2018 7:29 pm

Re: Hide field depending on dropdown

Post by Roboroadie » Mon Jan 15, 2018 4:04 am

I’m trying to hide the custom fields option add in, based on client. my needs are as follows :
When a client is selected from the drop down only one specific client would trigger the custom fields option drop down to be required. No other clients need it. So it could be hidden. If this is even possible.

Uashbjo
Posts: 13
Joined: Tue Oct 24, 2017 9:41 pm

Re: Hide field depending on dropdown

Post by Uashbjo » Tue Jan 16, 2018 3:15 pm

In the file "time_script.tpl" I added this at line 106. It makes the custom field visible or hidden depending on the activity dropdown field.

Code: Select all

function handleCustomFieldControl() {
  var project_dropdown = document.getElementById("project");
  var cf1_field = document.getElementById("cf_1");
  var cf1_label = document.getElementById("cf_1td");
  if (project_dropdown.value == 3 ) {
    cf1_field.style.visibility = "visible";
    cf1_label.style.visibility = "visible";
  } else if (project_dropdown.value == 6 ) {
    cf1_field.style.visibility = "visible";
    cf1_label.style.visibility = "visible";
  } else {
    cf1_field.style.visibility = "hidden";
    cf1_label.style.visibility = "visible";
  }
}

Roboroadie
Posts: 3
Joined: Sun Jan 14, 2018 7:29 pm

Re: Hide field depending on dropdown

Post by Roboroadie » Thu Jan 18, 2018 12:18 am

Awesome ! Thank you , I will give this a try .

Uashbjo
Posts: 13
Joined: Tue Oct 24, 2017 9:41 pm

Re: Hide field depending on dropdown

Post by Uashbjo » Thu Jan 18, 2018 12:24 pm

No problem. But I'm a newbie so there might be better ways to do it more efficiently.

Uashbjo
Posts: 13
Joined: Tue Oct 24, 2017 9:41 pm

Re: Hide field depending on dropdown

Post by Uashbjo » Tue Jan 23, 2018 4:50 pm

Does anybody know how I could change the code to check the value instead of the index in the dropdown menu? In the line I want to change the "6" to a string value.

Code: Select all

else if (project_dropdown.value == [b]6 [/b]) 
Thank you!

wrc
Posts: 251
Joined: Tue May 25, 2010 8:30 pm

Re: Hide field depending on dropdown

Post by wrc » Tue Jan 23, 2018 6:27 pm

Try this after controls are initialized.

Code: Select all

<script>
  var e = document.getElementById("project");
  var projectName = e.options[e.selectedIndex].text;
  alert(projectName);
</script>

Post Reply