Can't disable (set to read-only, protect, gray-out etc.) a field
Asked Answered
P

2

0

I've run this code:

Xrm.Page.data.entity.attributes.get("subject").setValue("Beep");;
alert(Xrm.Page.ui.controls.get("subject").setDisabled);
Xrm.Page.ui.controls.get("subject").setDisabled(true);

As expected, I get the text Beep into the field. As expected, the alert tells me the contents of the method (and as far I can tell, they're doing what they're supposed to).

However, the Control itself doesn't get disabled. What am I doing wrong?

I believe that I saw one example of different approach (something more between get and setDisabled but after a few hours of googling, I'm starting to conclude that I must've been halucinating or wish-thinking.

Polley answered 28/12, 2012 at 16:53 Comment(0)
C
1

Your code is correct, so it should be working. The syntax used by @Daryl is correct to. Those two lines are equivalent. The shorter one is just syntactic sugar shortening the other. So, you should use his.

Xrm.Page.ui.controls.get("subject").setDisabled(true);
Xrm.Page.getControl("subject).setDisabled(true);

If you're alerting out and getting the contents of the method, it means that you're hitting the right component and the correct method. Yet, so say that despite the call, the control doesn't get disabled. I think you're wrong.

Here's what I think happens. The control gets disabled, then, before you have time to notice it, the form get updated, rendering away your disable operation.

Keep in mind that unlike the field data, the property of being disabled doesn't get stored to the database. If you design a field as protected, it'll stay that way. But if you set such a property from the JavaScript code on the client-side, the appearance is only going to last until a reload of the page is performed.

So, if you need to keep the fields disabled, either make them so from the GUI designer or fire an onLoad method doing it for you.

Convention answered 29/12, 2012 at 0:16 Comment(0)
B
1

I use the getControl function and it works fine. should be in the form:

Xrm.Page.getControl(controlId).setDisabled(disabled);

And remember, disabled controls will not be updated unless you set the submit mode to "always".

Boozy answered 28/12, 2012 at 17:27 Comment(0)
C
1

Your code is correct, so it should be working. The syntax used by @Daryl is correct to. Those two lines are equivalent. The shorter one is just syntactic sugar shortening the other. So, you should use his.

Xrm.Page.ui.controls.get("subject").setDisabled(true);
Xrm.Page.getControl("subject).setDisabled(true);

If you're alerting out and getting the contents of the method, it means that you're hitting the right component and the correct method. Yet, so say that despite the call, the control doesn't get disabled. I think you're wrong.

Here's what I think happens. The control gets disabled, then, before you have time to notice it, the form get updated, rendering away your disable operation.

Keep in mind that unlike the field data, the property of being disabled doesn't get stored to the database. If you design a field as protected, it'll stay that way. But if you set such a property from the JavaScript code on the client-side, the appearance is only going to last until a reload of the page is performed.

So, if you need to keep the fields disabled, either make them so from the GUI designer or fire an onLoad method doing it for you.

Convention answered 29/12, 2012 at 0:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.