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

Extending ReferenceManyField with new type cause dupes choices to appear #649

Open
armellarcier opened this issue Sep 2, 2015 · 4 comments

Comments

@armellarcier
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@jpetitcolas
Copy link
Contributor

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

@Kmaschta
Copy link
Contributor

Related to #1225

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants