Skip to content

Commit

Permalink
add minlength
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtakoe committed May 10, 2016
1 parent 4a121b5 commit 9507de0
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 14 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#### Bug Fixes

- **oi-select:** `select as` works correct with object data source
- **oi-select:**
- `select as` works correct with object data source
- `minlength` is minimum length of query for searching

- **list-placeholder:** placeholder for dropdown list if no items found

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Use `oi-select` directive:
* `newItemFn` — function which get query and return new item object or promise. F.e. `'addItem($query)'`
* `removeItemFn` — function which get removed item model and return any value or promise. If promise was rejected, item wouldn't removed. F.e. `'removeItem($item)'`
* `maxlength` — maximum number of characters allowed in the input
* `minlength` — minimum number of characters for searching

### oiSelect service
* `options` — default options which we can override in `oiSelectProvider.options`
Expand Down
10 changes: 8 additions & 2 deletions dist/select-tpls.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ angular.module('oi.select')
editItem: false,
newItem: false,
closeList: true,
saveTrigger: 'enter tab blur'
saveTrigger: 'enter tab blur',
minlength: 0
},
version: {
full: '0.2.21',
Expand Down Expand Up @@ -533,10 +534,12 @@ angular.module('oi.select')
});

scope.$watch('query', function(inputValue, oldValue) {
if (saveOn(inputValue.slice(0, -1), inputValue.slice(-1))) {
if (saveOn(inputValue.slice(0, -1), inputValue.slice(-1)) || //terminated symbol
String(inputValue).length < options.minlength) { //length less then minlength
return;
}


//We don't get matches if nothing added into matches list
if (inputValue !== oldValue && (!scope.oldQuery || inputValue) && !matchesWereReset) {
listElement[0].scrollTop = 0;
Expand Down Expand Up @@ -799,6 +802,9 @@ angular.module('oi.select')
}

function click(event) {
//query length less then minlength
if (scope.query.length < options.minlength) return;

//option is disabled
if (oiUtils.contains(element[0], event.target, 'disabled')) return;

Expand Down
2 changes: 1 addition & 1 deletion dist/select-tpls.min.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions dist/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ angular.module('oi.select')
editItem: false,
newItem: false,
closeList: true,
saveTrigger: 'enter tab blur'
saveTrigger: 'enter tab blur',
minlength: 0
},
version: {
full: '0.2.21',
Expand Down Expand Up @@ -533,10 +534,12 @@ angular.module('oi.select')
});

scope.$watch('query', function(inputValue, oldValue) {
if (saveOn(inputValue.slice(0, -1), inputValue.slice(-1))) {
if (saveOn(inputValue.slice(0, -1), inputValue.slice(-1)) || //terminated symbol
String(inputValue).length < options.minlength) { //length less then minlength
return;
}


//We don't get matches if nothing added into matches list
if (inputValue !== oldValue && (!scope.oldQuery || inputValue) && !matchesWereReset) {
listElement[0].scrollTop = 0;
Expand Down Expand Up @@ -799,6 +802,9 @@ angular.module('oi.select')
}

function click(event) {
//query length less then minlength
if (scope.query.length < options.minlength) return;

//option is disabled
if (oiUtils.contains(element[0], event.target, 'disabled')) return;

Expand Down
2 changes: 1 addition & 1 deletion dist/select.min.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions docs/examples/validation/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ <h2>Validation</h2>

<br/>

<p>Also you can set maximum number of characters allowed in the input</p>
<p>Also you can set maximum number of characters allowed in the input and minimum number of characters to prevent searching if query is too small</p>
<div class="row">
<div class="col-md-8">
<oi-select
oi-options="item.name for item in shopArr"
ng-model="bundle3"
oi-select-options="{
maxlength: 3
maxlength: 4,
minlength: 2
}"
placeholder="Select"
></oi-select>
Expand All @@ -96,7 +97,8 @@ <h2>Validation</h2>
oi-options="item.name for item in shopArr"
ng-model="bundle3"
oi-select-options="{
maxlength: 3
maxlength: 4,
minlength: 2
}"
</div>
<div class="col-md-4"><pre>
Expand Down
11 changes: 8 additions & 3 deletions src/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ angular.module('oi.select')
});

scope.$watch('query', function(inputValue, oldValue) {
if (saveOn(inputValue.slice(0, -1), inputValue.slice(-1))) {
return;
}
//terminated symbol
if (saveOn(inputValue.slice(0, -1), inputValue.slice(-1))) return;

//length less then minlength
if (String(inputValue).length < options.minlength) return;

//We don't get matches if nothing added into matches list
if (inputValue !== oldValue && (!scope.oldQuery || inputValue) && !matchesWereReset) {
listElement[0].scrollTop = 0;
Expand Down Expand Up @@ -466,6 +468,9 @@ angular.module('oi.select')
}

function click(event) {
//query length less then minlength
if (scope.query.length < options.minlength) return;

//option is disabled
if (oiUtils.contains(element[0], event.target, 'disabled')) return;

Expand Down
3 changes: 2 additions & 1 deletion src/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ angular.module('oi.select')
editItem: false,
newItem: false,
closeList: true,
saveTrigger: 'enter tab blur'
saveTrigger: 'enter tab blur',
minlength: 0
},
version: {
full: '0.2.21',
Expand Down

0 comments on commit 9507de0

Please sign in to comment.