Dynamic CRM 2013學習筆記(十六)用JS控制Tab可見,可用

來源:互聯網
上載者:User

標籤:crm 2013   crm   

一個Form裡經常會有好幾個Tab,有時要根據一些條件設定哪些Tab可用,可見。下面就介紹下如何用JS對Tab進行控制。

1. 控制可見

 

function setTabVisableByName(tabName, flag) {
    var control = Xrm.Page.ui.tabs.get(tabName);
    control.setVisible(flag);
}

這裡flag是true或false

 

2. 控制可用

看了上面的可見代碼,是不是以為可用也這麼簡單呢?其實我們把上面的setVisible改成setDisabled,會報錯:

control.setDisabled is not a function

 

先看下Xrm.Page 的對象階層:

可以看到 tabs –> sections –> controls 這個階層。

於是就寫了下面的代碼:

 

function disableTab(tabName, flag) {
    debugger;
    var sections = Xrm.Page.ui.tabs.get(tabName).sections.get();
    for (var j in sections) {
        var controls = sections[j].controls.get();
        for (var i in controls) {
            var control = controls[i];
            var controlType = control.getControlType();
            if (controlType != "iframe" && controlType != "webresource" && controlType != "subgrid") {
                if (control != null && control.getDisabled() == !flag) {
                    control.setDisabled(flag);
                }
            }
        }
    }
}

 

其中有一行是判斷control的類型:

if (controlType != "iframe" && controlType != "webresource" && controlType != "subgrid") {

這行代碼是後來加上的,因為當時出現了一個很奇怪的現象,建立或查看記錄時,沒問題,但建立儲存時總是會報這個錯誤:

control.setDisabled is not a function

加上這行後就ok了,這個問題當時花了我好長時間。

 

如果是要把整個form都禁用呢,可以用下面的代碼,更簡潔:

Xrm.Page.ui.controls.forEach(function (control, index) {
        var controlType = control.getControlType();
        if (controlType != "iframe" && controlType != "webresource" && controlType != "subgrid")) {
            control.setDisabled(flag);
        }
    });

Dynamic CRM 2013學習筆記 系列匯總

Dynamic CRM 2013學習筆記(十六)用JS控制Tab可見,可用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.