0

I define a custom field on ng-admin to upload a file. I use the documentation here.

I include the repository admin-config.

Define my CustomeFileField as follows:

import Field from "./admin-config/lib/Field/Field.js";

class CustomFileField extends Field {
    constructor(name) {
        super(name);
        this._type = 'customfile';
        this._id = undefined; 
        this._entity_field = undefined;
        this._upload_information = {};
}

uploadInformation(baseUrl) {
    if(!argument.length) return this._upload_information;
    if(typeof this._id === 'undefined') {
        throw new Error('You must provide a valid id for the entity');
    }
    this._upload_information = { 
                'url': baseUrl + 'fr/media/upload?ref_id='+ this._id +'&ref=OpnRecipeBundle\\Entity\\Recipe', 
                 'apifilename': 'files' 
    };
    return this; 
}

// value of the entity id
id(value) {
    if(!argument.length) return this._id;
    this._id = value;
    return this;
}
//name of the field in the entity id
entityField(value) {
    if(!argument.length) return this._entity_field;
    this._entity_field = value;
    return this;
    }
}
export default CustomFileField;

And I defined the corresponding view accordind to the documentation.

I register both with the current:

nga.registerFieldType('customfile', require('./CustomFileField.js'));
fvp.registerFieldView('customfile', require('./CustomFileFieldView.js')); 

Then I call my freshly new define type with:

nga.field('itsname','customfile');

Nevertheless I have the current error, after transpiling everything properly:

Error: [$injector:modulerr] Failed to instantiate module opnAdmin due to: this._fieldTypes[t] is not a constructor

When logging things carrefully, it seems that the field typeTypes collection has many entries, one for each type, for the native ng-admin types, it's a function, but for my new defined type ( 'customfile') it's an object, hence the call off the new operator throw an error. Any solution for that folks?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
user2626210
  • 115
  • 5
  • 13
  • The use of require('CustomField.js') return an object, if we use import CustomField from 'CustomField.js' instead it returns a function and it works. – user2626210 Apr 06 '16 at 14:28

1 Answers1

0

The use of require('CustomField.js') return an object, if we use import CustomField from 'CustomField.js' instead it returns a function and it works.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
user2626210
  • 115
  • 5
  • 13