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

Impossible to extend reference_many field #1225

Open
gartner opened this issue Oct 10, 2016 · 2 comments
Open

Impossible to extend reference_many field #1225

gartner opened this issue Oct 10, 2016 · 2 comments

Comments

@gartner
Copy link

gartner commented Oct 10, 2016

Using ng-admin alpha7.

It doesn't seem to be possible to extend a reference_many field.

I copied the ReferenceManyField.js and ReferenceManyFieldView.js, renamed them, and renamed the class in it.
I then registered my new field as tag_reference_many.

When creating a field of this type 'tag_reference_many' it does render, but no labels are added in the displayed 'select multiple':

    nga.field('categories', 'tag_reference_many')
        .label('Kategorier')
        .targetEntity(categories)
        .targetField(nga.field('navn'))
        .validation({required: true})

If I create the field with the above, but just as a 'reference_many' it is working as it should, displaying the labels.

When creating the field definition, I did nothing more than copying the reference_many field type/field view files and renaming the field._type in them.

@gartner
Copy link
Author

gartner commented Oct 11, 2016

The problem seems to be this piece of code:

getReferences(fields, withRemoteComplete, optimized = null) {
        let references = fields.filter(f => f.type() === 'reference' || f.type() === 'reference_many');

from the file Utils/ReferenceExtractor.js in admin-config.

There is a pull request (marmelab/admin-config#74) that should fix this, but it does not work for me.

@faboulaws
Copy link

I managed to inherit both reference and reference_many fields. If you want the new Field to keep functioning like the reference_many field, you must not override the _type in the child class. Some of the logic in the code is too coupled to the reference fields.
Since you should not override the _type, you dont need to register a view. Instead set the template in the constructor of your child field class.

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