ng-admin
ng-admin copied to clipboard
Add filter to reference depending on another reference
Hi.
i have 2 reference fields, for example, permissions and users, and i want to filter users filed depending on permissions choice, something like:
myEntity.creationView()
.fields([
nga.field('permission_id', 'reference')
.targetEntity(permissions)
.targetField(nga.field('name')),
nga.field('user_id', 'reference')
.targetEntity(users)
.remoteComplete(true)
.targetField(nga.field('name'))
.permanentFilters({ 'permission_id': entry.values.permission_id })
.template('<ma-reference-field ng-if="entry.values.permission_id" field="::field" value="value" datastore="::datastore"></ma-reference-field>')
]);
Is it possible?
nope, for that permanentFilters()
should accept a function. But it's a great feature idea, I suggest you give it a try and send us a PR!
Seems like this was possible before? Still, even if one was able to reduce the dataset by means of a callback, this would only work as long as the chosen field (in this example permission_id) is not changed. I would be willing to implement this feature but I'm not really sure how to go about the synchronization aspect.
I suggest you give it a try and send us a PR!
Have no such experience to code it =(
Hey, i got the exact same situation, i wanted to restrict stores based on the current location of my entry. It would be awesome to let permanentFilters having access to the current entry value (callback with entry argument ?).
Hey, I confirm, there are lots of situation where it could be really good :D No experience with Angular too :/ will have a look if I can do something ...
+1 for this feature. maybe we shouldn't reuse the name "permanentFilters", maybe a new call
.filters(function(entry) {
return { 'projectId': entry.project.id };
}
+1
+1
+1
+1
+1
+1
= +6
+1
Sorry guys, but as we said in our last blog post about ng-admin, we're focusing our efforts on admin-on-rest and no longer on ng-admin.
I see that this specific issue is popular, but it isn't a security issue nor a bug so we won't invest for it for now. I can only suggest to make your own PR for it!
I just made it work perfectly combining the codes from various topics:
- https://github.com/marmelab/admin-config/pull/64/files
- https://github.com/marmelab/ng-admin/pull/938/commits/eac1a6fd0d5ae78174f08a56506e99aa695906ec (thanks a lot Vasia Korobkin !)
and adding "scope.refresh('');" to this piece of code:
if (!!field._getPermanentFilters) { scope.$watch('entry.values', function(newValue, oldValue){ field._getPermanentFilters(newValue); scope.refresh(''); }, true); }
This is indeed an extra useful feature!! :)
I also made it work. @JasnahKolhn's advice helped alot.