web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Portal: Hide Or Disable Field based on other fields value

(1) ShareShare
ReportReport
Posted on by 238

Hi,

Im trying to hide or disable a field on Portal, but i cant figure it out. I've tried the two JS below and added it to the Entity Form. I also as a test, added it in 3 places, the Entity Form, Web Page, and using the Front-Side editor (not sure which is the preferred method). No luck.

Its a custom entity. Lets assume the field names are new_field1 an new_field2. I want to hide new_field2 if new_field1 is null

$(document).ready(function() {

  $("#new_field2").change(SetFieldsVisibility);
  $("#new_field2").change();
});

function SetFieldsVisibility() {
  var Field1 = $("#new_field1").val();

  if (Field1 === null)
  {
    $("#new_field2").closest("tr").hide();
  }
  else
  {
    $("#new_field2").closest("tr").show();
  }
}
function setFieldDisplay(new_field1, new_field2) {
   if (new_field1 == null) {
       $("#" + new_field2).closest("tr").show()
   }
   else if (new_field1 !== null) {
       $("#" + new_field2).closest("tr").hide()
   }

}


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    Have a look at this link and see if this helps to get your code working

    community.dynamics.com/.../299169

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at

    Hi JoeO,

    Following code works on create case form. Can you try something like this on portal form. 

    3660.portal.png

    $(document).ready(function () {
    	console.log("ready!");
    	$("#title").change(function () {
    		alert($("#title").val());
    		if ($("#title").val() === null || $("#title").val() === "") {
    			$("#description").hide();
    		} else {
    			$("#description").show();
    		}
    	});
    });

    Thanks

    Justin Jose

  • Mahendar Pal Profile Picture
    45,095 on at

    Easy option is to first test your code on browser console to make sure your fields are hidden or not, you can't use full code but you can check with few line of code, once you are good you can use it any place entityform, web page etc

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    The code to retrieve the value from a field also depend upon the type of field i.e. is it a check box, radio button , dropdown etc. And also once the value is retrieved you need to compare it with the value it can return i.e. null, undefined, integer etc.

    In general the code you have shared should work but will agree with Mahen's suggestion that you should furst test the values in browser console.

    Are you trying to create a general helper liabrary?

    Hope this helps.

  • JO-30091535-0 Profile Picture
    238 on at

    The following worked for me. Really posting for my own (or anyone elses) reference. If the field "Field-To-Validate" is null, then hide "Field1" and "Field2". Else, show...

    $(document).ready(function() {
    SetFieldsVisibility();
    $("#Field-To-Validate").change(SetFieldsVisibility);
    
    });
    
    function SetFieldsVisibility() {
    var FieldToCheck = $("#Field-To-Validate").val();
    if (FieldToCheck === "")
    {
    $("#Field1-To-Hide").closest("tr").hide();
    $("#Field2-To-Hide").closest("tr").hide();
    }
    else
    {
    $("#Field1-To-Show").closest("tr").show();
    $("#Field2-To-Show").closest("tr").show();
    }
    }


  • Suggested answer
    Charles Abi Khirs Profile Picture
    3,569 on at

    Hello JoeO,

    In addition to the above, I would add that you should not hide all the "tr" element, because if the field to be hidden/shown is located in a row with another fields, all the fields in the same row will be hidden/shown.

    That's why, I suggest to hide the closest "td" instead of the closest "tr" that lead to hide/show only the "td" cell of the needed field

  • Suggested answer
    Summer Garg Profile Picture
    585 on at

    Hi JoeO,

    Check this below link,

    crmhub.blogspot.com/.../how-to-use-java-script-in-adx-studio.html

  • JO-30091535-0 Profile Picture
    238 on at

    Thanks to all of you. Helpful stuff!

    One more question. How do i Clear a field, and how do i perform it in the same function (if possible).

    For example, if Field3 contains data, then clear and hide Field1 (Field1 happens to be the "Field-To-Validate" field mentioned above)

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at

    Hi JoeO,

    can you try something like below code please.

    function SetFieldsVisibility() {
        var FieldToCheck = $("#Field-To-Validate").val();
    
        if ($("#Field3").val() !== "" || $("#Field3").val() !== null) {
            $("#Field1-To-Hide").val("");
            $("#Field1-To-Hide").closest("tr").hide();
        } else {
    
            if (FieldToCheck === "") {
                $("#Field1-To-Hide").closest("tr").hide();
                $("#Field2-To-Hide").closest("tr").hide();
            } else {
                $("#Field1-To-Show").closest("tr").show();
                $("#Field2-To-Show").closest("tr").show();
            }
        }
    }

    Thanks

    Justin Jose

  • SOUNDHARYA.N.V Profile Picture
    165 on at

    HI,

    Try this $("#subject").val(null);

    It differs for different data types

    For lookup $("#regardingobjectid").val(null); this wont work

    $("#regardingobjectid_name").val(null); this will work

    Similarly it is different for different data types.

    What is your field3 data type?

    Thank You

    Soundharya

    If found useful, please mark the answer as verified

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans