AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 01.04.2009, 05:07   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
Microsoft Dynamics CRM Team Blog: CRM 4.0: Checkbox style Multi-Select Picklist
Источник: http://blogs.msdn.com/crm/archive/20...-picklist.aspx
==============

Our guest blogger is CRM MVP Jim Wang joining us from Reading England. Jim blogs regularly at Microsoft Dynamics CRM – Jim Wang’s technical blog [MVP].

CRM 4.0 doesn't have many out-of-box user controls, such as multi-select picklists. The standard CRM picklist can only save one value in the database, it's not easy to extend this functionality, in addition, you have to deal with the Advanced Find feature.



You can make a picklist multi-selectable by enable the picklist multiple attribute , e.g: crmForm.all.new_picklist.multiple = true; And then save the selected values somewhere else. However, it does not very impressive the user because the user has to use the CTRL key to select options, which is not user-friendly (Thanks for Alastair Westland (PM @ Parity) who work with me to improve the interface design:)


The script below will draw a checkbox style multi-select picklist control on the CRM form, and then get options from the real picklist attribute. So how to use it?


1. Create a standard picklist attribute with all options in CRM, put it on the CRM Form. e.g: new_picklist;
2. Create another nvarchar attribute in CRM to save the selected text, put it on the CRM Form and hide the label. e.g. new_picklistvalue;
3. Put the following script in the Form.OnLoad() event.

X++:
/*
Checkbox style Multi-Select Picklist
author: Jim Wang @ January 2009
[url]http://jianwang.blogspot.com[/url]
*/

// PL - the picklist attribute; PLV - used to save selected picklist values  
var PL = crmForm.all.new_picklist;  
var PLV = crmForm.all.new_picklistvalue;  

if( PL != null && PLV != null )  
{  
  PL.style.display = "none";  
  PLV.style.display = "none";  

  // Create a DIV container  
  var addDiv = document.createElement("<div style='overflow-y:auto; height:80px; border:1px #6699cc solid; background-color:#ffffff;' />");  
  PL.parentNode.appendChild(addDiv);  
  
  // Initialise checkbox controls  
  for( var i = 1; i < PL.options.length; i++ )  
  {  
    var pOption = PL.options[i];  
    if( !IsChecked( pOption.text ) )  
      var addInput = document.createElement("<input type='checkbox' style='border:none; width:25px; align:left;' />" );  
    else  
      var addInput = document.createElement("<input type='checkbox' checked='checked' style='border:none; width:25px; align:left;' />" );  
  
    var addLabel = document.createElement( "<label />");  
    addLabel.innerText = pOption.text;  

    var addBr = document.createElement( "  
"); //it's a 'br' flag  

    PL.nextSibling.appendChild(addInput);  
    PL.nextSibling.appendChild(addLabel);  
    PL.nextSibling.appendChild(addBr);  
  }  
  
  // Check if it is selected  
  function IsChecked( pText )  
  {  
    if(PLV.value != "")  
    {  
      var PLVT = PLV.value.split("||");  
      for( var i = 0; i < PLVT.length; i++ )  
      {  
        if( PLVT[i] == pText )  
          return true;  
      }  
    }  
    return false;  
  }  

  // Save the selected text, this filed can also be used in Advanced Find  
  crmForm.attachEvent( "onsave" , OnSave);  
  function OnSave()  
  {  
    PLV.value = "";  
    var getInput = PL.nextSibling.getElementsByTagName("input");  

    for( var i = 0; i < getInput.length; i++ )  
    {  
      if( getInput[i].checked)  
      {  
        PLV.value += getInput[i].nextSibling.innerText + "||";  
      }  
    }  
  }  
}
Cheers,

Jim Wang



Источник: http://blogs.msdn.com/crm/archive/20...-picklist.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Последний раз редактировалось Aleksey_M; 02.04.2009 в 12:19. Причина: код с оригинала скопировал
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Microsoft Dynamics CRM Team Blog: Building Rich-Client Dashboards for Microsoft Dynamics CRM with Windows Presentation Foundation Blog bot Dynamics CRM: Blogs 1 31.03.2009 13:24
Microsoft Dynamics CRM Team Blog: List Web Part for Microsoft Dynamics CRM 4.0 Deployment Scenarios Blog bot Dynamics CRM: Blogs 0 30.01.2009 22:05
Microsoft Dynamics CRM Team Blog: Microsoft Dynamics CRM 4.0 Bookshelf Blog bot Dynamics CRM: Blogs 1 22.01.2009 04:46
Microsoft Dynamics CRM Team Blog: Highlight: Available downloads for Microsoft Dynamics CRM Blog bot Dynamics CRM: Blogs 0 05.11.2008 22:05
Microsoft Dynamics CRM Team Blog: Top 14 Microsoft Dynamics CRM Sites and Downloads Blog bot Dynamics CRM: Blogs 0 14.07.2008 13:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 10:26.