无法禁用(设置为只读,保护,变灰等)字段 [英] Can't disable (set to read-only, protect, gray-out etc.) a field

查看:149
本文介绍了无法禁用(设置为只读,保护,变灰等)字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了以下代码:

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

正如预期的那样,我将文本 Beep 输入该字段。正如预期的那样,警报告诉我该方法的内容(据我所知,他们正在执行应做的事情。)



但是,控件本身不会被禁用。我在做什么错了?



我相信我看到了一个不同方法的示例( get 之间的更多内容)和 setDisabled ,但经过几个小时的搜索之后,我开始得出结论,我必须一直在思考或希望进行思考。

解决方案

您的代码正确,因此应该可以使用。@Daryl使用的语法正确。这两行是等效的。较短的一行只是语法糖,它缩短了另一行。

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

如果重新发出警报并获取方法的内容,这意味着您正在使用正确的组件和正确的方法,但是,说尽管调用,该控件不会被禁用。我想你错了。



这就是我想发生的情况。控件被禁用,然后,在您没有时间注意到它之前,表单将被更新,从而取消了禁用操作。



请记住,与字段不同数据,则被禁用的属性不会存储到数据库中。如果您将某个字段设计为受保护的字段,它将保持这种状态。但是,如果您从客户端的JavaScript代码设置了这样的属性,则外观只会持续到重新加载页面为止。



因此,如果您需要禁用这些字段,则可以从GUI设计器中进行设置,或者触发 onLoad 方法来为您执行此操作。

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.

解决方案

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.

这篇关于无法禁用(设置为只读,保护,变灰等)字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆