Show / hide field in web forms

hello all ,

I have tried to show / hide field based on other field’s value from DocType “Depends On”.
But it’s working for desk view only and not for webform.

is there any way to do this , or should i made it using form js ?

Depends on work well with the form view. As for the webform you don’t get the option for depends on while selecting the webform fields right?

I guess you’ll have to handle the hide/show from the webform’s js itself.

This is a fun problem. At the highest docfield level, all form elements are the same: <div class="form-group">:

From my website if you want to inspect it yourself.

So you’ll have to do some j/query selector to find the element and then move up two parents. I use data-fieldname because there will be one unique result as long as it’s a form built in Frappe. I have gotten into trouble when I’ve built my own HTML forms, but that’s an aside.

Here are a bunch of options from MDN for regular JS query selectors.

A piece of advice though, either use jquery or don’t. I’ve wasted a bunch of time when I tried something with a jquery .find and then returned it outside of jquery, which meant I was getting two results each time (one from jQuery, one from some vanilla JS.) Frappe ships with jQuery, so for the time being go ahead and use it, but that won’t last forever.

@Zlash65

yes the webform don’t have the option for depends on
i made depends on in doctype which my webform rely on , so if i have a condition on this doctype
it is supposed to executed also in webform and that’s did not happened

We have some work going on to refactor Webforms to use the Desk forms:

https://github.com/frappe/frappe/pull/5537

But it will probably come after v11