Add custom type to Ng-admin

642 Views Asked by At

I want add custom types to Ng-admin. I didn't find complete info or sample to do it. As a sample, I want add next types: embedded object, embedded_list type, parted combo box and others.

My confuse is what syntax and structure of TypeField and TypeFieldView files.

1

There are 1 best solutions below

2
On

You custom type should extend the Field type at least, or another existing type.

// in path/to/MyCustomDateField.js
// ES6 version
import DateField from 'admin-config/lib/Field/DateField';
export default class MyCustomDateField extends DateField {
    formatSmall() {
        return this.format('small');
    }
}

// ES5 version
var DateField = require('admin-config/lib/Field/DateField');
function MyCustomDateField(name) {
    DateField.call(this, name);
}
MyCustomDateField.prototype = new DateField();
MyCustomDateField.prototype.formatSmall = function() {
    return this.format('small');
}
module.exports = MyCustomDateField;

As a side note, please don't post your question to too many places (e.g. here, in the ng-admin gitter, and in the ng-admin bugtracker). This gives us more work to provide support.