Sunday, 30 July 2017

Field Validations - Adxstudio and CRM Portal


Hello Everyone, As we all know that XRM Model is not supported on Adx and CRM Portal. Therefore we cannot use CRM Forms scripts and Business Rules to perform Client side validation on Portal Entity Forms.

Though we have Entity Form Metadata in Adxstudio and CRM Portal to perform lot of validations but that is also not work for few of cases.

Today in this article I am going to share some Tips and Tricks to play with Custom JavaScript to perform various client side validations on Adxstudio and CRM Portal.


Hide/Show Fields on Entity Forms :


Below are the syntax that you can use to hide/show the entity forms fields (Text, Lookup, Option Set, Date Field etc)

$(document).ready(function(){

// To Hide
$("#fieldlabelId").hide();
$("#fieldvalueId").hide();

// To Show
$("#fieldlabelId").show();
$("#fieldvalueId").show();

});

or

$(document).ready(function(){

// To Hide
$('#fieldlabelId').parent().parent().hide();

// To Show
$('#fieldlabelId').parent().parent().show();

});

Note : Rather Hide/Show Text Field Label and Textbox separately you can use above syntax to Hide/Show the whole Text field control (Label + Textbox)

Enable/Disable Fields on Entity Forms :


Text Field -


$(document).ready(function(){

// Disable the field
$("#textboxId").prop('disabled',true);

// Enable the field
$("#textboxId").prop('disabled',false);

});

Lookup Field -


$(document).ready(function(){

disableLookup('regardingobjectid_name', 'regardingobjectid_entityname');

});

function disableLookup(LookupNameID, LookupEntityNameID) {
    
    var L_EN_ID = '#' + LookupEntityNameID;
    var L_N_ID = '#' + LookupNameID;
    $(L_EN_ID).next().remove();
    $(L_N_ID).css('width', '329px');
}


Optionset Field -


$('#sw_premisetype').prop("disabled", true);



Hide/Show Section on Entity Forms :


Hide Section -


$('table[data-name="section_name"]').closest('fieldset').hide();

Show Section -


$('table[data-name="section_name"]').closest('fieldset').show();


Disable/Enable Section on Entity Forms :


Disable Field -


$('table[data-name="sec_AccountDetails2"]').closest('fieldset').find("input,button,textarea,select").attr("readonly", true);


Enable Field -


$('table[data-name="sec_AccountDetails2"]').closest('fieldset').find("input,button,textarea,select").attr("readonly", false);

Note : If you get any requirement to make the portal section disables, Rather making it Disable, you must always make it Read-only, because disable section fields values does not store in CRM.
Above syntax is to make the section Read-only instead of Disabled.


Hide/Show Tab on Entity Forms :


Hide Tab-


var tab = $('table[data-name="section_name"]').closest('.tab');
var label = tab.prev('.tab-title');
tab.hide();
label.hide();


Show Section -


var tab = $('table[data-name="section_name"]').closest('.tab');
var label = tab.prev('.tab-title');
tab.hide();
label.show();


Hide/Show Date-time Control on Entity Forms :


Right Click on Date Field Control Textbox and click on Inspect. Now copy the value of 'aria-describedby' attribute.

$('input[aria-describedby="<copied value of aria-describedby>"]').parent().parent().hide();

Above syntax use to Hide/Show Date-Time Textbox Control

Below syntax use to Hide/Show Date-Time Textbox Control

$(''datefield_label").hide();



Please feel free to get in touch with me if you want to get advice for some more validations. I'd love to hear from you.

3 comments:

  1. How can I show/hide the fields on load? I have tried hiding the fields on entity form load using the code:
    $(document).ready(function(){
    $('#firstname').closed('tr').hide();
    });
    But the field was shown intially and then was hidden.
    Is there a way to not show the field at all instead hiding it in the CRM Form Editor?

    ReplyDelete
  2. Special thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to

    (hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time.

    Contact him now and thank me later.

    ReplyDelete
  3. Special thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to

    (hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time.

    Contact him now and thank me later.

    ReplyDelete

Blogger Widgets