简体   繁体   English

在HTML中为ComboBox设置选择和输入元素的样式

[英]Styling Select and Input Element for ComboBox in HTML

For a custom user control in MS Dynamics CRM-style, I need to have a combobox, which is not natively present in HTML. 对于MS Dynamics CRM风格的自定义用户控件,我需要有一个组合框,而该组合框本身不是HTML格式的。

My idea was to put an input and a select after each other. 我的想法是互相补充inputselect The Problem is that I can 问题是我可以

  • use the select control's arrow itself, but then I need to get rid of the value part of the select control. 使用select控件的箭头本身,但是接下来我需要摆脱select控件的值部分。 It is at least present when I mark via moving the mouse with button down, even with color:transparent , or 至少当我通过按下按钮移动鼠标进行标记(即使使用color:transparent

  • lay another element on top, but then I cannot open the dropdown programmatically. 在顶部放置另一个元素,但随后我无法以编程方式打开下拉菜单。

The control must as well stretch along the input element to full size of the whole control. 控件还必须沿着input元素拉伸到整个控件的完整大小。

Also, in the Internet Explorer, the dropdown list also moves with the currently selected element, so if I select, say, the third option , when opening next time, the first two option s will be displayed above. 另外,在Internet Explorer中,下拉列表也随当前选定的元素一起移动,因此,如果我选择第三个option ,则在下次打开时,前两个option将显示在上方。

Since this custom control will be displayed in an iframe , I have to use a select so that the dropdown-part will be rendered outside the iframe as well and does not get cut off. 由于此自定义控件将显示在iframe ,因此我必须使用select以便下拉部分也将呈现在iframe之外并且不会被截断。 This is required. 这是必需的。

Please see https://jsfiddle.net/z7tcrtdg/ to get a rough idea. 请参阅https://jsfiddle.net/z7tcrtdg/以获得大概的想法。

You should use size attribute in select element to apply any styles to your options or select. 您应该在select元素中使用size属性将任何样式应用于您的选项或select。

You might be surprised but MS implement drop down lists as you describe by default. 您可能会感到惊讶,但是MS会默认执行您描述的下拉列表。 Let me explain: you see input element and when you click on it js function apply "display:none" for input and remove this attribute from expanded select (and something else). 让我解释一下:您看到输入元素,然后单击js函数,将“ display:none”应用于输入,并从扩展的select(及其他内容)中删除此属性。 I have a big experience in this kind of unsupported customizations. 我在这种不受支持的自定义方面有丰富的经验。

Since this custom control will be displayed in an iframe, I have to use a select so that the dropdown-part will be rendered outside the iframe as well and does not get cut off. 由于此自定义控件将显示在iframe中,因此我必须使用select,以便下拉部分也将呈现在iframe之外,并且不会被截断。 This is required. 这是必需的。

There is two ways to achieve this goal: 1. Set enough space for your html web-resource 2. Put control's markup directly to standard markup (extremely unrecommended and unsupported) 有两种方法可以实现此目标:1.为您的html Web资源设置足够的空间2.将控件的标记直接置于标准标记中(极不推荐和不支持)

Hope this help. 希望能有所帮助。

UPD: UPD:

In case you don't have enough information about available space for your custom control there is only one way of implementation. 如果您没有足够的信息来了解自定义控件的可用空间,则只有一种实现方式。 This way is put markup of your control directly into standard HTML form markup. 这样可以将控件的标记直接放入标准HTML表单标记中。 It's highly important to understand all consequences before you choose this way as a solution. 选择这种方式作为解决方案之前,了解所有后果非常重要。

So, I would like to start from control markup. 因此,我想从控件标记开始。 Please take a look at code block below: 请看下面的代码块:

<tr height="24">
<td class="ms-crm-ReadField-Normal ms-crm-FieldLabel-LeftAlign">
    <span class="ms-crm-InlineEditLabel">
        <span class="ms-crm-InlineEditLabelText" style="max-width:125px;text-align:Left;">Sale Status</span>
        <div class="ms-crm-InlineField withReqIcon"></div>
        <img alt="Required" src="/_imgs/frm_required.gif" class="ms-crm-Inline-RequiredLevel">
    </span>
</td>
<td class="ms-crm-Field-Data-Print" colspan="4">
    <div class="highContrast ms-crm-Inline-Chrome status">
        <div id="scn_sctps_valueContainer" class="ms-crm-Inline-Value">
            <span>None</span>
        </div>
        <div id="scn_sctps_ctrlContainer"
             class="ms-crm-Inline-Edit ms-crm-Inline-OptionSet noScrool ms-crm-Inline-HideByZeroHeight"
             style="display: none;">
            <select class="ms-crm-SelectBox ms-crm-Inline-OptionSet-AutoOpen" controlmode="normal"
                    id="scn_sctps_select" size="7">
                <option value="bs1">None</option>
                <option value="bs2">Qualification</option>
                <option value="bs621740000">Needs Analysis</option>
                <option value="bs621740001"
                        style="border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(128, 130, 133); background-color: rgb(241, 241, 241);">
                    Proposal/Quote
                </option>
                <option value="sb621740001621745001"
                        style="padding-left: 20px; background-color: rgb(249, 249, 249);">In Production
                </option>
                <option value="sb621740001621745002"
                        style="padding-left: 20px; background-color: rgb(249, 249, 249);">Prepared and Passed to
                    Sales
                </option>
                <option value="sb621740001621745003"
                        style="padding-left: 20px; background-color: rgb(249, 249, 249);">Rejected by Production
                </option>
                <option value="sb621740001621745004"
                        style="padding-left: 20px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(128, 130, 133); background-color: rgb(249, 249, 249);">
                    Rejected By Sales
                </option>
                <option value="bs621740003">Proposal sent</option>
                <option value="bs621740002">Negotiation/Review</option>
                <option value="bs621740004">Postponed</option>
            </select>
        </div>
        <span class="ms-crm-Inline-LockIcon" style="display:none;">
            <img src="/_imgs/inlineedit/locked.png" alt="locked">
        </span>
    </div>
</td>
</tr>

Appearance: 出现:

控制外观

The difference between select with defined size is that select appears as already expanded and you don't need to make any interactions with him (it's related to your attempts to open select programmatically). 具有定义size的select之间的区别在于,select显示为已展开,并且您无需与他进行任何交互(这与您以编程方式打开select的尝试有关)。

You might be surprised but as I mention earlier this state of select (already expanded with defined size attribute) it's the only way to apply any CSS styles to option tag inside. 您可能会感到惊讶,但正如我之前提到的select状态(已经使用定义的size属性进行扩展),这是将所有CSS样式应用于option标签的唯一方法。

Markup description: 标记说明:

First td node contains elements which represent label (field display name) near your control. 第一个td节点包含表示控件附近标签(字段显示名称)的元素。 Second td contains markup related directly to dropdown control and contains two primary parts: 'label' (display name of currently selected value) and select which is in hidden state by default. 第二个td包含与下拉控件直接相关的标记,并包含两个主要部分:“ label”(当前选定值的显示名称)和select缺省情况下处于隐藏状态。

Your responsibilities: 您的职责:

You should handle and properly respond to all user interactions with your control. 您应该处理并正确响应与控件的所有用户交互。 There is a shortlist of control functionality that you should implement by yourself: 您应该自己实现控制功能的简短列表:
1. Set actual value to label and select on form load 1.设置标签实际值并在表格加载时select
2. Store result of user interactions. 2.存储用户交互的结果。 MS's form engine can't automatically determine changes in your control. MS的表单引擎无法自动确定控件中的更改。
3. Show select and hide 'label' element when user clicks on 'label' and backward operation. 3.当用户单击“标签”和向后操作时,显示select并隐藏“标签”元素。

How to hide element in terms of Dynamics CRM form implementation: 如何根据Dynamics CRM表单实现隐藏元素:

Please take a look at a div element with id scn_sctps_ctrlContainer . 请查看ID为scn_sctps_ctrlContainerdiv元素。 You can find style="display:none;" 您可以找到style="display:none;" and CSS class called ms-crm-Inline-HideByZeroHeight . 和称为ms-crm-Inline-HideByZeroHeight CSS类。 These two things help you to hide element. 这两件事可以帮助您隐藏元素。

In case you have any questions please feel free to ask. 如有任何疑问,请随时提出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM