Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Add filter to reference depending on another reference #938

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@
refreshDelay: 200,
searchQuery: function(search) { return { q: search }; }
})
.permanentFilters(function(entry) {
return {author: entry['author.name']};
})
]);

comment.editionView()
Expand Down
5 changes: 5 additions & 0 deletions src/javascripts/ng-admin/Crud/field/maReferenceField.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export default function maReferenceField(ReferenceRefresher) {
}));
scope.$broadcast('choices:update', { choices: initialChoices });
} else {
if (!!field._getPermanentFilters) {
scope.$watch('entry.values', function(newValue, oldValue){
field._getPermanentFilters(newValue);
}, true);
}
// ui-select doesn't allow to prepopulate autocomplete selects, see https://github.com/angular-ui/ui-select/issues/1197
// let ui-select fetch the options using the ReferenceRefresher
scope.refresh = function refresh(search) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export default {
getReadWidget: () => '<ma-reference-column field="::field" value="::value" datastore="::datastore"></ma-reference-column>',
getLinkWidget: () => '<ma-reference-link-column entry="::entry" field="::field" value="::value" datastore="::datastore"></ma-reference-link-column>',
getFilterWidget: () => '<ma-reference-field field="::field" value="value" datastore="::datastore"></ma-reference-field>',
getWriteWidget: () => '<ma-reference-field field="::field" value="value" datastore="::datastore"></ma-reference-field>'
getWriteWidget: () => '<ma-reference-field entry="::entry" field="::field" value="value" datastore="::datastore"></ma-reference-field>'
};