ng-admin
ng-admin copied to clipboard
Extending ReferenceManyField with new type cause dupes choices to appear
Hi!
I managed to extend ReferenceManyField
like this :
import ReferenceManyField from 'admin-config/lib/Field/ReferenceManyField';
class ReferenceManyCustomField extends ReferenceManyField {
constructor(name) {
super(name);
this._type = 'reference_many_custom';
}
}
export default ReferenceManyCustomField;
But now the choices
displayed include the current field value.
If I remove the line where I change the _type
property, it goes back to normal.
Any hints on why this is happening?
If that's ok I'll submit a PR where ReferenceRefresher
will check the field's removeDuplicateReferences
method :
if (field.type() === 'reference_many' || field.type() === 'choices' || ( field.removeDuplicateReferences && field.removeDuplicateReferences() ) ) {
promise = promise.then(formattedResults => this._removeDuplicates(formattedResults, currentValue));
}
I could also add the method to reference_many
and choices
fields in admin-config?
Well that would mean updating react-admin also so...
Indeed, such a _shouldRemoveDuplicate
field is a more robust way to handle that. I'm :+1: with it.
Related to #1225