i define custom field on ng-admin upload file. use documentation here.
i include repository admin-config.
define customefilefield follows:
import field "./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 valid id entity'); } this._upload_information = { 'url': baseurl + 'fr/media/upload?ref_id='+ this._id +'&ref=opnrecipebundle\\entity\\recipe', 'apifilename': 'files' }; return this; } // value of entity id id(value) { if(!argument.length) return this._id; this._id = value; return this; } //name of field in entity id entityfield(value) { if(!argument.length) return this._entity_field; this._entity_field = value; return this; } } export default customfilefield;
and defined corresponding view accordind documentation.
i register both current:
nga.registerfieldtype('customfile', require('./customfilefield.js')); fvp.registerfieldview('customfile', require('./customfilefieldview.js'));
then call freshly new define type with:
nga.field('itsname','customfile');
nevertheless have current error, after transpiling properly:
error: [$injector:modulerr] failed instantiate module opnadmin due to: this._fieldtypes[t] not constructor
when logging things carrefully, seems field typetypes collection has many entries, 1 each type, native ng-admin types, it's function, new defined type ( 'customfile') it's object, hence call off new operator throw error. solution folks?
the use of require('customfield.js') return object, if use import customfield 'customfield.js' instead returns function , works.
Comments
Post a Comment