Skip to content

Commit

Permalink
Merge pull request #788 from kenegozi/remote-complete-filtering
Browse files Browse the repository at this point in the history
remote-complete filtering
  • Loading branch information
fzaninotto committed Nov 16, 2015
2 parents 1879f4d + 8dcaa12 commit 0f8719f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/javascripts/ng-admin/Crud/field/maChoiceField.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export default function maChoiceField($compile) {
});

var refreshAttributes = '';
var itemsFilter = '| filter: {label: $select.search}';
if (field.type().indexOf('reference') === 0 && field.remoteComplete()) { // FIXME wrong place to do that
scope.refreshDelay = field.remoteCompleteOptions().refreshDelay;
refreshAttributes = 'refresh-delay="refreshDelay" refresh="refresh({ $search: $select.search })"';
itemsFilter = '';
}

var choices = scope.choices() ? scope.choices : (field.choices ? field.choices() : []);
Expand All @@ -40,7 +42,7 @@ export default function maChoiceField($compile) {
var template = `
<ui-select ng-model="$parent.value" ng-required="v.required" id="{{ name }}" name="{{ name }}">
<ui-select-match allow-clear="{{ !v.required }}" placeholder="{{ placeholder }}">{{ $select.selected.label }}</ui-select-match>
<ui-select-choices ${refreshAttributes} repeat="item.value as item in choices | filter: {label: $select.search} track by $index">
<ui-select-choices ${refreshAttributes} repeat="item.value as item in choices ${itemsFilter} track by $index">
{{ item.label }}
</ui-select-choices>
</ui-select>`;
Expand Down
4 changes: 3 additions & 1 deletion src/javascripts/ng-admin/Crud/field/maChoicesField.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export default function maChoicesField($compile) {
scope.v = field.validation();

var refreshAttributes = '';
var itemsFilter = '| filter: {label: $select.search}';
if (field.type().indexOf('reference') === 0 && field.remoteComplete()) {
scope.refreshDelay = field.remoteCompleteOptions().refreshDelay;
refreshAttributes = 'refresh-delay="refreshDelay" refresh="refresh({ $search: $select.search })"';
itemsFilter = '';
}

var choices = field.choices ? field.choices() : [];
Expand All @@ -35,7 +37,7 @@ export default function maChoicesField($compile) {
var template = `
<ui-select ${scope.v.required ? 'ui-select-required' : ''} multiple ng-model="$parent.value" ng-required="v.required" id="{{ name }}" name="{{ name }}">
<ui-select-match placeholder="{{ placeholder }}">{{ $item.label }}</ui-select-match>
<ui-select-choices ${refreshAttributes} repeat="item.value as item in choices | filter: {label: $select.search}">
<ui-select-choices ${refreshAttributes} repeat="item.value as item in choices ${itemsFilter}">
{{ item.label }}
</ui-select-choices>
</ui-select>`;
Expand Down

0 comments on commit 0f8719f

Please sign in to comment.