0

I'm trying to write a custom type to create a cascading dropdown. I start with defining a new custom type extending reference type. The problem is that no matter what I write inside the class body the component doesn't show up with no error. Here is the new field class:

import ReferenceField from "admin-config/lib/Field/ReferenceField";

class CascadeParentField extends ReferenceField {
 constructor(name) {
        super(name);
        this._type = 'cascade_parent';
        this._cascadeReference = null;
    } 
}
export default CascadeParentField;

and the paired FieldView class:

export default {
    getReadWidget:   () => '<ma-reference-column field="::field" value="::value" datastore="::datastore"></ma-reference-column>',
    getLinkWidget:   () => '<ma-reference-link-column entry="::entry" field="::field" value="::value" datastore="::datastore"></ma-reference-link-column>',
    getFilterWidget: () => '<ma-reference-field field="::field" value="value" datastore="::datastore"></ma-reference-field>',
    getWriteWidget:  () => '<ma-reference-field field="::field" value="value" datastore="::datastore"></ma-reference-field>'
};

While in main.js:

myApp.config(['NgAdminConfigurationProvider', 'FieldViewConfigurationProvider', function(nga, fvp) {
    nga.registerFieldType('cascade_parent', require('./types/CascadeParentField'));
    fvp.registerFieldView('cascade_parent', require('./types/CascadeParentFieldView'));
}]);

Any idea? I tried to debug but didn't find any issue...

deck80
  • 21
  • 4

1 Answers1

0

The nga.registerFieldType using a require will probably generate an exception that 'CascadeParentField' is not a constructor, so you should instead do an import:

import CascadeParentField from './types/CascadeParentField.js';
...
myApp.config(['NgAdminConfigurationProvider', 'FieldViewConfigurationProvider', function (nga, fvp) {
nga.registerFieldType('cascade_parent', AmountType);
...
}

Besides that, my guess is that documentation is currently broken since that is not stated there but I found it in another SO post:

ng-admin does not recognize custom field view

And by the way I have the same issue (not being able to do a custom field view).

Community
  • 1
  • 1
Boris
  • 26
  • 4