zoukankan      html  css  js  c++  java
  • Toggle or Hidden MS CRM Tab

    Often times we need to toggle the visiblity of an element based on the value of a field. This JScript file adds the methods to accomplish this by calling the setVisibility function. For example, in an onChange event for new_mypicklist I can call:

    1. setVisibility('section','new_mypicklist','section_main',42);  

    This hides the section_main section if the value is not 42, which simplifies the process of hiding and showing relevant information.

    I also like to use checkboxes to handle the visibility of elements, but checkbox values dont’ change until they lose focus. To work around the issue, I register an onClick event during the form load instead of using the onChange event. This unsupported method allows me to modify the value onClick and change the visibility immediately. To use this I just need to call it in the onload:

    1. registerToggle('section', 'new_checkbox', 'section_main');  

    If you wanted to hide it when new_checkbox was false (or no), then you would need to specify the value, 0.

    1. registerToggle('section', 'new_checkbox', 'section_main',0);  

    JScript: visibility.js

    This is the main javascript file… visibility.js that you would need to add and reference as a web resource in CRM 2011, everything except for the registerToggle uses supported methods.

    1. function registerToggle(t, attr, c, v) {  
    2.     if (typeof (v) === "undefined" || v === null) {  
    3.         var v = 1;  
    4.     }  
    5.     var ctrl = Xrm.Page.ui.controls.get(attr);  
    6.     var a = ctrl.getAttribute();  
    7.     var el = document.getElementById(attr);  
    8.   
    9.     // Build Toggle Function  
    10.     var f = "var ef=function() { " +  
    11.               "var a = Xrm.Page.data.entity.attributes.get(attr); " +  
    12.               "a.setValue(!a.getValue()); " +  
    13.               "setVisibility('" + t + "','" + attr + "','" + c + "'," + v + ");" +  
    14.               " };";  
    15.   
    16.     eval(f);  
    17.   
    18.     // Attach to click event  
    19.     el.attachEvent('onclick', ef, false);  
    20.   
    21.     // Set visibility  
    22.     setVisibility(t, attr, c, v);  
    23. }  
    24.   
    25. function setVisibility(t, attr, c, v) {  
    26.     switch (t.toLowerCase().charAt(0)) {  
    27.         //tab  
    28.         case 't': setTabVisibility(attr, c, v);  
    29.             break;  
    30.         //section  
    31.         case 's': setSectionVisibility(attr, c, v);  
    32.             break;  
    33.         //control  
    34.         case 'c': setControlVisibility(attr, c, v);  
    35.             break;  
    36.         //navigation  
    37.         case 'n': setNavigationVisibility(attr, c, v);  
    38.             break;  
    39.     }  
    40. }  
    41.   
    42. function setNavigationVisibility(attributename, navitemname, value) {  
    43.     var attribute = Xrm.Page.data.entity.attributes.get(attributename);  
    44.     var navitem = Xrm.Page.ui.navigation.items.get(navitemname);  
    45.     if (navitem === null)  
    46.     {  
    47.         return;  
    48.     }  
    49.     navitem.setVisible(attribute.getValue() == value);  
    50. }  
    51.   
    52. function setTabVisibility(attributename, tabname, value) {  
    53.     var attribute = Xrm.Page.data.entity.attributes.get(attributename);  
    54.     var tab = Xrm.Page.ui.tabs.get(tabname);  
    55.     if (tab === null)  
    56.     {  
    57.         return;  
    58.     }  
    59.     tab.setVisible(attribute.getValue() == value);  
    60. }  
    61.   
    62. function setSectionVisibility(attributename, sectionname, value) {  
    63.     var attribute = Xrm.Page.data.entity.attributes.get(attributename);  
    64.     var tabs = Xrm.Page.ui.tabs.get();  
    65.     for(var i in tabs) {  
    66.         var tab = tabs[i];  
    67.         var section = tab.sections.get(sectionname);  
    68.         if (section !== null) {  
    69.             section.setVisible(attribute.getValue() == value);  
    70.             return;  
    71.         }  
    72.     }  
    73. }  
    74.   
    75. function setControlVisibility(attributename, controlname, value) {  
    76.     var attribute = Xrm.Page.data.entity.attributes.get(attributename);  
    77.     var control = Xrm.Page.ui.controls.get(controlname);  
    78.     if (control === null)  
    79.     {  
    80.         return;  
    81.     }  
    82.     control.setVisible(attribute.getValue() == value);  

  • 相关阅读:
    IsBadReadPtr|IsBadWritePtr调试崩溃
    VSCode配置python调试环境
    Visual Studio Code 如何编写运行 C、C++ 程序?
    使用nginx做反向代理
    Win10环境下配置VScode的C++编译环境
    关于java 获取 html select标签 下拉框 option 文本内容 隐藏域
    【VSCode】Windows下VSCode编译调试c/c++【更新 2018.03.27】
    VS Code 配置 C/C++ 环境
    改变你一生的编辑器:VSCode使用总结
    CentOS7,安装Tomcat8.5、JDK1.8,并设置开机启动(Linux CentOS Tomcat、JDK+Tomcat、Tomcat开机自启动)
  • 原文地址:https://www.cnblogs.com/janmson/p/2184997.html
Copyright © 2011-2022 走看看