Skip to content

Commit

Permalink
Clarify custom types in configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Aug 25, 2015
1 parent eae12f2 commit 8b9d186
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion doc/Custom-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ myEntity.listView().fields([
]);
```

`nga.field()` is a factory method returning an instance of the `Field` class. Such instances are containers for your application configuration. For some types, the instance returned by `nga.field()` is a specialized subclass of `Field`, with methods specific to this type (like `format()` for the 'date' type). These methods are later used in the presentation layer to get the specific configuration for that type.
`nga.field()` is a factory method returning an instance of [the `Field` class](https://github.com/marmelab/admin-config/blob/master/lib/Field/Field.js). Such instances are containers for your application configuration. For some types, the instance returned by `nga.field()` is a specialized subclass of `Field`, with methods specific to this type (like `format()` for [the `DateField` class](https://github.com/marmelab/admin-config/blob/master/lib/Field/DateField.js)). These methods are later used in the presentation layer to get the specific configuration for that type.

You can change the field class returned by `nga.field()` for a given type at configuration time. For instance, to change the `Field` class for the 'date' type:

Expand All @@ -23,6 +23,30 @@ myApp.config(['NgAdminConfigurationProvider', function(nga) {
}]);
```

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

```js
// 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;
```

Use the same technique to add a new type.

```js
Expand Down

0 comments on commit 8b9d186

Please sign in to comment.