crm表单中Section的所有字段的setDisable [英] setDisable for all fields of a Section in a Crm Form

查看:152
本文介绍了crm表单中Section的所有字段的setDisable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果其他字段的值为true,我需要禁用一个部分,通常我会这样做:

I need to disable a section if a value from other field is true, normally I would do:

function disableSection1(disabledStatus){
    Xrm.Page.getControl("section1field1").setDisabled(disabledStatus);
    Xrm.Page.getControl("section1field2").setDisabled(disabledStatus);
    Xrm.Page.getControl("section1field3").setDisabled(disabledStatus);
    Xrm.Page.getControl("section1field4").setDisabled(disabledStatus);
}

但我必须为很多部分这样做,所以我正在寻找一个功能如下:

but i have to do this for many sections, so I am looking for a function like this:

function sectionSetDisabled(tabNumber, sectionNumber, disabledStatus){
    //some code..
}


推荐答案

我见过的大多数答案都有用使用sectionLable并进行以下比较:
controlIHave.getParent()。getLabel()==该部分的名称

Most answers I have seen you have use the use the sectionLable and do the following comparison: controlIHave.getParent().getLabel()=="name of the section

但经过一些试验,我发现我可以使用 Xrm.Page.ui.tabs.get(tabNumber).sections.get(sectionNumber).controls.get()获取部分内的控件。这允许我使用以下函数:

But after some trials I found I could use Xrm.Page.ui.tabs.get(tabNumber).sections.get(sectionNumber).controls.get() to get the controls inside the section. That allowed me to use the following function:

function sectionSetDisabled(tabNumber, sectionNumber, disablestatus) {
    var section = Xrm.Page.ui.tabs.get(tabNumber).sections.get(sectionNumber);
    var controls = section.controls.get();
    var controlsLenght = controls.length;

    for (var i = 0; i < controlsLenght; i++) {
        controls[i].setDisabled(disablestatus)
    }
}

使用 controls [i] .getAttribute()然后你可以获得一个部分的属性。

by using controls[i].getAttribute() you can then get the attributes of a section.

我最终创建了一个对象,允许我禁用并清除部分中的所有字段:

I ended up creating a object that allows me to disable and clear all the fields in a section:

function sectionObject(tabNumber, sectionNumber) {
    var section = Xrm.Page.ui.tabs.get(tabNumber).sections.get(sectionNumber);

    this.setDisabled = function (disablestatus) {
        var controls = section.controls.get();
        var controlsLenght = controls.length;
        for (var i = 0; i < controlsLenght; i++) {
            controls[i].setDisabled(disablestatus)
        }
    };

    this.clearFields = function () {
        var controls = section.controls.get();
        var controlsLenght = controls.length;
        for (var i = 0; i < controlsLenght; i++) {
            controls[i].getAttribute().setValue(null);
        }
    };

}

var section=new sectionObject(0,1);
section.setDisabled(true/false);

这篇关于crm表单中Section的所有字段的setDisable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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