How to Disable / Enable the Fields, Buttons and DateTime Fields with Common Code. In Dynamics 365 CRM Portals.

Summary : How to Disable / Enable the Fields, Buttons and DateTime Fields In Dynamics 365 CRM Portals.

Common Code:

function TextFieldsdisableEnable(fields, flag) {
    if (fields !== "") {
        var fieldschema = fields.split(",");
        for (var item = 0; item < fieldschema.length; item++) {
            if (fieldschema !== "" && $("#" + fieldschema[item]) !== null) {
                $("#" + fieldschema[item]).prop('disabled', flag);
            }
        }
    }
}

function DatetimeFieldsdisableEnable(fields, flag) {
    if (fields !== "") {
        var fieldschema = fields.split(",");
        for (var item = 0; item < fieldschema.length; item++) {
            if (fieldschema !== "" && $("#" + fieldschema[item]) !== null) {
                if (flag) {
                    var dateField = $("#" + fieldschema[item]);
                    // Get ‘Text’ field of Date Control
                    var displayField = dateField.nextAll(".datetimepicker").children("input");
                    // Get ‘Calendar’ Icon of Date Control
                    var dateIcon = dateField.nextAll(".datetimepicker").children("span");
                    // Make ‘Text’ field of Date Control Read-Only
                    displayField.attr("readonly", "readonly");
                    // Hide ‘Calendar’ Icon
                    dateIcon.css("display", "none");
                }
                else {
                    var dateField = $("#" + fieldschema[item]);
                    // Get ‘Text’ field of Date Control
                    var displayField = dateField.nextAll(".datetimepicker").children("input");
                    // Get ‘Calendar’ Icon of Date Control
                    var dateIcon = dateField.nextAll(".datetimepicker").children("span");
                    // Make ‘Text’ field of Date Control Read-Only
                    //displayField.attr("enabled", "enabled");
                    displayField.removeAttr("readonly");
                    // Hide ‘Calendar’ Icon
                    dateIcon.css("display", "");
                }
            }
        }
    }
}

How to Use Example:

// the first parameter is list of fields/button id's which you want to disable and second parameter pass true/false , true for disable and false for enable.

TextFieldsdisableEnable("portal_test,portal_tetsoptionset,edittBtn", true);

DatetimeFieldsdisableEnable("portal_testdate", true);



1 comment:

  1. Thanks for this Useful article.

    Keep Sharing your knowledge to help others.

    Dynamics 365 customer portal

    ReplyDelete

Popular Posts