Skip to content

Commit

Permalink
add enable/disable method to Selected & Dropdown, resolved #743
Browse files Browse the repository at this point in the history
  • Loading branch information
Minwe committed Nov 25, 2015
1 parent 311319a commit c54a715
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

**JS:**

- `NEW` #734 Dropdown、Selected 新增 `enable``disable` 方法;
- `Improved` #733 Selected 增加超过最多可选值时提示接口;
- `Improved` #749 Selected 允许添加一个空的 `<option>` 实现不自动选择第一项。

Expand Down
6 changes: 6 additions & 0 deletions docs/javascript/selected.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ $(function() {
- `dropUp: 0`: 是否为上拉,默认为 `0` (`false`)
- `placeholder`: 占位符,默认读取 `<select>``placeholder` 属性,如果没有则为 `点击选择...`

#### 方法

- `$().selected('disable')`: 禁用选框(`v2.5`
- `$().selected('enable')`: 启用选框(`v2.5`
- `$().selected('destroy')`: 销毁实例

#### 事件

| 事件名称 | 描述 |
Expand Down
8 changes: 8 additions & 0 deletions js/ui.dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ Dropdown.prototype.close = function() {
}
};

Dropdown.prototype.enable = function() {
this.$toggle.prop('disabled', false);
},

Dropdown.prototype.disable = function() {
this.$toggle.prop('disabled', true);
},

Dropdown.prototype.checkDimensions = function() {
if (!this.$dropdown.length) {
return;
Expand Down
15 changes: 15 additions & 0 deletions js/ui.selected.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var $ = require('jquery');
var UI = require('./core');
// require('./ui.dropdown');

// Make jQuery :contains Case-Insensitive
$.expr[':'].containsNC = function(elem, i, match, array) {
Expand Down Expand Up @@ -113,6 +114,10 @@ Selected.prototype.init = function() {
// set select button styles
this.$selector.css({width: this.options.btnWidth});

if (this.$element[0].disabled) {
this.$selector.addClass(options.disabledClass);
}

this.$list = this.$selector.find('.am-selected-list');
this.$searchField = this.$selector.find('.am-selected-search input');
this.$hint = this.$selector.find('.am-selected-hint');
Expand Down Expand Up @@ -345,6 +350,16 @@ Selected.prototype.bindEvents = function() {
});
};

Selected.prototype.enable = function() {
this.$element.prop('disable', false);
this.$selector.dropdown('enable');
},

Selected.prototype.disable = function() {
this.$element.prop('disable', true);
this.$selector.dropdown('disable');
},

Selected.prototype.destroy = function() {
this.$element.removeData('amui.selected').show();
this.$selector.remove();
Expand Down

0 comments on commit c54a715

Please sign in to comment.