Skip to content

Commit

Permalink
Merge pull request #42 from Janking/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Janking authored Nov 28, 2018
2 parents 8645035 + 115f831 commit 82263fb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ Dropdown 会根据这个JSON来渲染 `select > option`
| 名称 | 描述 | 类型|默认|
| ----|-----|-----|----|
| readOnly|是否只读|Boolean|`false`|
|minCount|下限|Number|`0`|
|limitCount|选择上限|Number|`Infinity`|
| minCount|下限|Number|`0`|
| minCountErrorMessage|下限自定義錯誤消息|String|最低选择<mincount>个|
| limitCount|选择上限|Number|`Infinity`|
| limitCountErrorMessage|上限的自定义错误消息|String|最多可选择<limitCount>个|
| input|搜索框模板|HTML|`<input type="text" maxLength="20" placeholder="搜索关键词或ID">`|
| data|数据源|Array|`[]`|
| searchable|是否可开启搜索|Boolean|`true`|
Expand Down
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ <h2> Demo</h2>

$('.dropdown-mul-2').dropdown({
minCount: 2,
limitCount: 5,
minCountErrorMessage: 'You need to select at least 2 options!',
limitCount: 4,
limitCountErrorMessage: 'You cannot select more than 4 options!',
searchable: false,
choice: function () {
console.log('.dropdown-mul-2 picked')
Expand Down
14 changes: 12 additions & 2 deletions jquery.dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
var settings = {
readonly: false,
minCount: 0,
minCountErrorMessage: '',
limitCount: Infinity,
limitCountErrorMessage: '',
input: '<input type="text" maxLength="20" placeholder="搜索关键词或ID">',
data: [],
searchable: true,
Expand Down Expand Up @@ -92,10 +94,14 @@
var _config = _dropdown.config;
var $el = _dropdown.$el;
var $alert = $el.find('.dropdown-minItem-alert');
var alertMessage = _config.minCountErrorMessage;
clearTimeout(_dropdown.itemCountAlertTimer);

if ($alert.length === 0) {
$alert = $('<div class="dropdown-minItem-alert">\u6700\u4f4e\u9009\u62e9' + _config.minCount + '\u4E2A</div>');
if (!alertMessage) {
alertMessage = '\u6700\u4f4e\u9009\u62e9' + _config.minCount + '\u4E2A';
}
$alert = $('<div class="dropdown-minItem-alert">' + alertMessage + '</div>');
}

$el.append($alert);
Expand All @@ -110,10 +116,14 @@
var _config = _dropdown.config;
var $el = _dropdown.$el;
var $alert = $el.find('.dropdown-maxItem-alert');
var alertMessage = _config.limitCountErrorMessage;
clearTimeout(_dropdown.itemLimitAlertTimer);

if ($alert.length === 0) {
$alert = $('<div class="dropdown-maxItem-alert">\u6700\u591A\u53EF\u9009\u62E9' + _config.limitCount + '\u4E2A</div>');
if (!alertMessage) {
alertMessage = '\u6700\u591A\u53EF\u9009\u62E9' + _config.limitCount + '\u4E2A';
}
$alert = $('<div class="dropdown-maxItem-alert">' + alertMessage + '</div>');
}

$el.append($alert);
Expand Down
Loading

0 comments on commit 82263fb

Please sign in to comment.