ng-admin icon indicating copy to clipboard operation
ng-admin copied to clipboard

Extending ReferenceManyField with new type cause dupes choices to appear

Open armellarcier opened this issue 8 years ago • 4 comments

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?

armellarcier avatar Sep 02 '15 10:09 armellarcier

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));
}

armellarcier avatar Sep 02 '15 10:09 armellarcier

I could also add the method to reference_many and choices fields in admin-config? Well that would mean updating react-admin also so...

armellarcier avatar Sep 02 '15 10:09 armellarcier

Indeed, such a _shouldRemoveDuplicate field is a more robust way to handle that. I'm :+1: with it.

jpetitcolas avatar Sep 02 '15 11:09 jpetitcolas

Related to #1225

Kmaschta avatar Nov 18 '16 22:11 Kmaschta