cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DewiCR
New Member

Can't Lock two same field in one form using javascript

I have a form that contain two same fields 'Nama Mentor PIC' with logical name 'ecom_namamentor'

I want to lock them using javascript, but when I run the application only 1 field is locked while the others are not.
even though both fields have the same logical name, and in javascript I have set it to be locked but it doesn't work.
how can i lock those two fields? Did I miss something?

 

this is javascript code

Screenshot 2022-04-13 102553.png

 

and this is what the form field looks like when javascript is run

WhatsApp Image 2022-04-13 at 10.23.24.jpeg

2 REPLIES 2
Mira_Ghaly
Dual Super User
Dual Super User

@DewiCR 

Please use the below and remember to pass executionContext as the first Parameter when registering the event

var formContext = executionContext.getFormContext();

var attr = formContext.getAttribute("ecom_namamentor");
attr.controls.forEach(function (control) {
control.setDisabled(true);
});

 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here
EricRegnier
Super User
Super User

Hi @DewiCR,

To supplement on @Mira_Ghaly post, the controls.get gets the first control but since you have more than 1 on the form that's why you would have to loop through each one as per the sample code. And Xrm.Page is deprecated so this is why the code uses formContext. Hope her post helps!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Users online (4,066)