如何在ember-widget中禁用多选组件

时间:2014-08-19 03:35:50

标签: select ember.js multiple-select

有没有办法从addepar的ember-widget中禁用多选组件?

这适用于单select-component

{{select-component
  contentBinding="selectCountries"
  prompt="Select a Country"
  value=selectSelected
  disabled=true
}}

同样不适用于multi-select-component

{{multi-select-component
  contentBinding="selectCountries"
  prompt="Select a Country"
  selections=multiSelectSelected
  disabled=true
}}

这是一个不起作用的JS bin示例。我仔细查看了源代码,但似乎并没有这个选项。

1 个答案:

答案 0 :(得分:0)

我能想到的最快速的方式,除了编辑源代码之外(更新JS bin):

我定义了一个Ember组件,它将一个字符串数组(selections)作为唯一参数。我使用了multi-select-component使用的所有类,所以我没有重新定义所有CSS:

<script type="text/x-handlebars" id="components/disabled-multi-select">
  <div class="ember-view ember-select multi-select-disabled" tabindex="-1">
    <div class="ember-select-container ember-select-multi dropdown-toggle js-dropdown-toggle">
      <ul class="form-control ember-select-choices">
        {{#each selection in selections}}
        <li class="ember-view ember-select-search-choice">
          <div>{{selection}}</div>
          <div class="ember-select-search-choice-close">×</div>
        </li>
        {{/each}}
      </ul>
    </div>
  </div>
</script>

然后我添加了一些css使它看起来像一个禁用的选择:

.ember-select.multi-select-disabled > .ember-select-container > .form-control {
  cursor: not-allowed;
  background-color: #EEE;
  opacity: 1;
}
.ember-select.multi-select-disabled > .ember-select-container .ember-select-search-choice {
  background-color: #D8D8D8;
  cursor: not-allowed;
}
.ember-select.multi-select-disabled > .ember-select-container .ember-select-search-choice .ember-select-search-choice-close {
  cursor: not-allowed;
}
.ember-select.multi-select-disabled > .ember-select-container .ember-select-search-choice .ember-select-search-choice-close:hover {
  background-color: #D8D8D8;
}

它的使用方式如下:

{{#if isInputDisabled}}
  // Stick your multi-select-component in here
{{else}}
  {{disabled-multi-select selections=multiSelectSelected}}
{{/if}}