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);



6 comments:

  1. Thanks for this Useful article.

    Keep Sharing your knowledge to help others.

    Dynamics 365 customer portal

    ReplyDelete
  2. Attend Business Analytics Training in Mumbai with 100% Syllabus Covered also Attend the Best Data Science Course in Mumbai. Faculty are From IIT & ISB. ExcelR is the Best Institute for Data Science Training in Mumbai
    Data Analytics Courses in Mumbai

    ReplyDelete
  3. Thanks for giving me the time to share such nice information. Thanks for sharing.

    Data Science Course
    Data Science Course in Marathahalli

    ReplyDelete
  4. I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article.

    Simple Linear Regression

    Correlation vs Covariance

    ReplyDelete
  5. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple linear regression
    data science interview questions

    ReplyDelete
  6. Attend The Data Science Courses From ExcelR. Practical Data Science Courses Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Science Courses. data science courses

    ReplyDelete

Popular Posts