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

  • 相关阅读:
    Python Day 72 Django框架 图书管理系统回顾ORM 正向查询、反向查询、跨表查询、Django终端打印SQL语句、ORM十三个必会操作总结
    Python Day 71 Django框架setting源码分析、基于该源码原理实现用户在暴露的setting文件中自定义的配置就使用用户配置的,没配置就是用全局默认的
    Python Day 70 利用Django框架做的一个bbs小项目
    Python Day 69 Django框架、Forms组件、forms组件的钩子函数、form组件前端处理逻辑三种方式、form常用字段及插件、Form所有内置字段、字段校验两种方式
    Python Day 68 Django框架、CBV源码简单理解
    Python Day 67 Dango框架图解(总结)、Wsgiref和uwsgi、前后端传输数据的编码格式、From表单和Ajax方式在前端往后端发送文件、补充一下页面清缓存
    python 学习分享-实战篇简单的ftp
    python 学习分享-面向对象2
    python 学习分享-实战篇选课系统
    python 学习分享-面向对象
  • 原文地址:https://www.cnblogs.com/janmson/p/2184997.html
Copyright © 2011-2022 走看看