diff --git a/UPGRADE-0.9.md b/UPGRADE-0.9.md
new file mode 100644
index 00000000..83b25554
--- /dev/null
+++ b/UPGRADE-0.9.md
@@ -0,0 +1,26 @@
+# Upgrade to 0.9
+
+## All fields have `.template()`
+
+All field types now support the `template()` method, which makes it easy to customize the look and feel of a particular field, without sacrificing the native features.
+
+For instance, if you want to customize the appearance of a `NumberField` according to its value:
+
+```js
+listview.fields([
+ nga.field('amount', 'number')
+ .format('$0,000.00')
+ .template('')
+]);
+```
+
+This removes the need for [custom types](doc/Custom-types.md) in a vast majority of cases.
+
+The `template` *field type* is deprecated and will be removed in future versions. Simply use the default field type together with the `template()` method instead:
+
+```js
+// before
+nga.field('name', 'template').template('{{ entry.values.name }}')
+// now
+nga.field('name').template('{{ entry.values.name }}')
+```
diff --git a/doc/Configuration-reference.md b/doc/Configuration-reference.md
index 4cc5e55e..ba12ab07 100644
--- a/doc/Configuration-reference.md
+++ b/doc/Configuration-reference.md
@@ -48,6 +48,7 @@ application
|-transform
|-attributes
|-cssClasses
+ |-template
|-validation
|-editable
```
@@ -283,10 +284,10 @@ Add filters to the list. Each field maps a property in the API endpoint result.
nga.field('q').label('Search').pinned(true)
]);
- Filter fields can be of any type, including `reference` and `template`. This allows to define custom filters with ease.
+ Filter fields can be of any type, including `reference`. This allows to define custom filters with ease.
listView.filters([
- nga.field('q', 'template').label('')
+ nga.field('q').label('')
.template('
'),
]);
@@ -379,12 +380,11 @@ A field is the representation of a property of an entity.
* [`reference` Field Type](#reference-field-type)
* [`referenced_list` Field Type](#referenced_list-field-type)
* [`reference_many` Field Type](#reference_many-field-type)
-* [`template` Field Type](#template-field-type)
### General Field Settings
* `nga.field(name, type)`
-Create a new field of the given type. Default type is 'string', so you can omit it. Bundled types include `string`, `text`, `wysiwyg`, `password`, `email`, `date`, `datetime`, `number`, `float`, `boolean`, `choice`, `choices`, `json`, `file`, `reference`, `reference_list`, `reference_many`, and `template`.
+Create a new field of the given type. Default type is 'string', so you can omit it. Bundled types include `string`, `text`, `wysiwyg`, `password`, `email`, `date`, `datetime`, `number`, `float`, `boolean`, `choice`, `choices`, `json`, `file`, `reference`, `reference_list`, and `reference_many`.
* `label(string label)`
Define the label of the field. Defaults to the uppercased field name.
@@ -466,6 +466,25 @@ A list of CSS classes to be added to the corresponding field. If you provide a f
return 'my-custom-css-class-for-list-header';
});
+* `template(String|Function)`
+All field types support the `template()` method, which makes it easy to customize the look and feel of a particular field, without sacrificing the native features.
+
+ For instance, if you want to customize the appearance of a `NumberField` according to its value:
+
+ listview.fields([
+ nga.field('amount', 'number')
+ .format('$0,000.00')
+ .template('')
+ ]);
+
+ The template scope exposes the following variables:
+
+ - `value`, `field`, `entry`, `entity`, and `datastore` in `listView` and `showView`
+ - `value`, `field`, `values`, and `datastore` in filters
+ - `value`, `field`, `entry`, `entity`, `form`, and `datastore` in `editionView` and `creationView`
+
+ Most of the time, `template()` is used to customize the existing ng-admin directives (like `ma-number-column>` in the previous example), for instance by decorating them. If you want to learn about these native directives, explore the [column](../src/javascripts/ng-admin/crud/column), [field](../src/javascripts/ng-admin/crud/field), and [fieldView](../src/javascripts/ng-admin/crud/fieldView) directories in ng-admin source.
+
* `defaultValue(*)`
Define the default value of the field in the creation form.
@@ -765,8 +784,3 @@ If set to false, all references (in the limit of `perPage` parameter) would be r
})
.perPage(10) // limit the number of results to 10
]);
-
-### `template` Field Type
-
-* `template(*)`
-Define the template to be displayed for fields of type `template` (can be a string or a function).
diff --git a/doc/Custom-pages.md b/doc/Custom-pages.md
index f5a35393..36684872 100644
--- a/doc/Custom-pages.md
+++ b/doc/Custom-pages.md
@@ -72,12 +72,12 @@ myApp.directive('sendEmail', ['$location', function ($location) {
## Including the Custom Directive in a Template Field
-Now the new directive is ready to be used inside a ng-admin field of type 'template':
+Now the new directive is ready to be used inside a ng-admin field using 'template()':
```js
post.showView().fields([
// ...
- nga.field('custom_action', 'template')
+ nga.field('custom_action')
.label('')
.template('')
]);
diff --git a/doc/Getting-started.md b/doc/Getting-started.md
index 7dd85af2..b3df2c78 100644
--- a/doc/Getting-started.md
+++ b/doc/Getting-started.md
@@ -504,10 +504,10 @@ Browse to the posts list, and you will see the full-text filter displayed on the
The full-text search isn't looking very good. Usually, a full-text filter widget has no label, a placeholder simply saying "Search", and a magnifying glass icon. How can you turn the current full-text input into that UI?
-Fortunately, ng-admin fields can benefit from the power of Angular.Js directives. Using the 'template' field type, you can specify the HTML template to use for rendering the field. And you can use any directive already registered in that HTML. Update the `nga.field('q')` definition as follows:
+Fortunately, ng-admin fields can benefit from the power of Angular.js directives. Using the `template()` field method, you can specify the HTML template to use for rendering the field. And you can use any directive already registered in that HTML. Update the `nga.field('q')` definition as follows:
```js
- nga.field('q', 'template')
+ nga.field('q')
.label('')
.pinned(true)
.template('
'),
diff --git a/doc/Theming.md b/doc/Theming.md
index c5db8320..7f66ab2b 100644
--- a/doc/Theming.md
+++ b/doc/Theming.md
@@ -32,9 +32,31 @@ myEntity.listView().fields([
]);
```
+## Customizing The Template For A Given Field
+
+All field types support the `template()` method, which makes it easy to customize the look and feel of a particular field, without sacrificing the native features.
+
+For instance, if you want to customize the appearance of a `NumberField` according to its value:
+
+```js
+listview.fields([
+ nga.field('amount', 'number')
+ .format('$0,000.00')
+ .template('')
+]);
+```
+
+The template scope exposes the following variables:
+
+* `value`, `field`, `entry`, `entity`, and `datastore` in `listView` and `showView`
+* `value`, `field`, `values`, and `datastore` in filters
+* `value`, `field`, `entry`, `entity`, `form`, and `datastore` in `editionView` and `creationView`
+
+Most of the time, `template()` is used to customize the existing ng-admin directives (like `ma-number-column>` in the previous example), for instance by decorating them. If you want to learn about these native directives, explore the [column](../src/javascripts/ng-admin/crud/column), [field](../src/javascripts/ng-admin/crud/field), and [fieldView](../src/javascripts/ng-admin/crud/fieldView) directories in ng-admin source.
+
## Customizing Directives Templates
-Using Angular's [`$provide`](https://docs.angularjs.org/api/auto/service/$provide) service, and the ability to decorate another provider, you can customize the templates of all the directives used by ng-admin. Here is an example of customization of the 'text' input field customization:
+Using Angular's [`$provide`](https://docs.angularjs.org/api/auto/service/$provide) service, and the ability to decorate another provider, you can customize the template of any directive used by ng-admin for your entire application. Here is an example of customization of the 'text' input field:
```js
var myApp = angular.module('myApp', ['ng-admin']);
diff --git a/examples/blog/config.js b/examples/blog/config.js
index d5e5e25a..11488953 100644
--- a/examples/blog/config.js
+++ b/examples/blog/config.js
@@ -163,7 +163,7 @@
.sortField('created_at')
.sortDir('DESC')
.listActions(['edit']),
- nga.field('', 'template').label('')
+ nga.field('').label('')
.template('')
]);
@@ -171,8 +171,7 @@
.fields([
nga.field('id'),
post.editionView().fields(), // reuse fields from another view in another order
- nga.field('custom_action', 'template')
- .label('')
+ nga.field('custom_action').label('')
.template('')
]);
@@ -197,7 +196,7 @@
.singleApiCall(ids => { return {'id': ids }})
])
.filters([
- nga.field('q', 'template')
+ nga.field('q')
.label('')
.pinned(true)
.template('