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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Custom javascript to c...
Power Pages
Suggested Answer

Custom javascript to control which form fields are editable.

(0) ShareShare
ReportReport
Posted on by 16
Hi,
 
I'm working on some custom javascript/CSS in a power pages form to control which fields are editable based on a list of field ids stored in a dataverse table. For text fields and dropdowns, my approach works the way I want: non‑editable fields are set to read‑only, while editable fields are highlighted and fully interactive.
However, I'm having issues with lookup fields. My code is supposed to remove/hide the buttons related to the non‑editable lookup fields and leave them intact for editable fields.  I’m having issue with the editable lookups, their buttons are being removed along with my non editable lookups.  Depending on what I try the buttons don’t reappear or if they are present they aren’t functional or sometimes they reappear for all lookups when I only want it for one editable lookup field. I don’t seem to be able to get the editable look up fields to act independently of the non-editable lookups. Does anyone have any suggestions how I could get this to work? 
 
    $("#EntityFormControl_EntityFormView :input, #EntityFormControl_EntityFormView select").each(function () {
        const field = $(this);
        const fieldId = field.attr("id") || "";
        const isEditable = editableFields.includes(fieldId);

        if (field.is("input[type='text'], textarea")) {
            if (!isEditable) {
                field.prop("readonly", true).attr("data-editable", "false");
            } else {
                field.prop("readonly", false).attr("data-editable", "true");
                field.addClass("highlight-editable");
            }
        } else {
            if (!isEditable) {
                field.attr("data-editable", "false");
            } else {
                field.attr("data-editable", "true");
                field.addClass("highlight-editable");
            }
        }
    });

    $("#EntityFormControl_EntityFormView [data-editable='false']").each(function () {
        const fieldContainer = $(this).closest(".input-group"); 
        if (fieldContainer.length) {
            fieldContainer.find("button.btn.btn-default.clearlookupfield").remove();
            fieldContainer.find("button.btn.btn-default.launchentitylookup").remove();
        }
    });
});
 
Categories:
I have the same question (0)
  • Suggested answer
    oliver.rodrigues Profile Picture
    9,368 Most Valuable Professional on at
  • 18121126-0 Profile Picture
    16 on at
    Hi @oliver.rodrigues, thank you for passing on that article. I looked through it, and while it does a great job of explaining how to set fields to read-only, my main challenge is making lookup fields editable again once selected from my list of editable fields.

    Right now, my code successfully applies read-only restrictions to text fields and dropdowns while allowing some to remain editable. However, lookup fields are behaving differently—if one is set to read-only, all of them become read-only, and I can't make an individual lookup editable again.

    Additionally, I ran into an issue when hiding the lookup buttons. .hide() only removes the 'launch lookup' button, leaving the 'clear lookup' button still visible. To fix this, I tried using .remove(), but that causes a new problem: when I remove the buttons for one read-only lookup, they disappear for all lookups, including the ones that should remain editable.

    I was expecting to be able to use logic so that only non-editable lookups lose their buttons, while editable ones retain full functionality. Do you have any suggestions for this specific issue? I have tried implementing your code but am still coming across similar issues. I just wonder am I not targeting the lookups correctly or is there something about lookups that prevents me from targeting them independently that I'm not aware of?

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 74 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 55

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard