Hide fields based on condition in a form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Requirement: When contact has value display contact and hide: u_name, u_phone, u_company and u_email else vise versa
function onLoad() {
var contact = g_form.getValue('contact');
if (contact) {
// Contact has value → show contact, hide other fields
g_form.setDisplay('contact', true);
g_form.setDisplay('u_name', false);
g_form.setDisplay('u_phone', false);
g_form.setDisplay('u_company', false);
g_form.setDisplay('u_email', false);
} else {
// No contact → hide contact, show other fields
g_form.setDisplay('contact', false);
g_form.setDisplay('u_name', true);
g_form.setDisplay('u_phone', true);
g_form.setDisplay('u_company', true);
g_form.setDisplay('u_email', true);
}
}
When the contact has value it hides the rest of the fields. But when the contact does not have value, it shows other fields and the also the contact field.
Why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The point is, it does not work onLoad. This is a read only form and therefor I don't need OnChange client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @vidhya_mouli ,
Could you please clarify whether the CONTACT field is auto-populated, or does the user need to enter the information manually?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
I implemented the UI policy so that when the User field has a value, the First name field is hidden. If the User field does not have a value, the First name field becomes visible and the User field is hidden. You can refer to the images below for further clarification.
If this response addressed your question, please mark it as Helpful and accept it as the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
This works for me too. The issue is when the user is empty. It is displaying both User and First name for me.