diff --git a/README.md b/README.md index 0ab58959..4ee385be 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,6 @@ These settings are available on all views. * `fields([field1, field2, ...])` Add fields to a view (columns to a list, or a form controls to a form). Each field maps a property in the API endpoint result. -Accept both field and array of fields. listView.fields([ nga.field('first_name'), @@ -222,11 +221,6 @@ Accept both field and array of fields. nga.field('age', 'number') ]); - listView.fields(nga.field('first_name'), [ - nga.field('last_name'), - nga.field('age', 'number') - ]); - * `fields()` Retrieve the list of fields added to a view. The result can be added to another view, to avoid repetition. * `title(String)` diff --git a/UPGRADE-0.7.md b/UPGRADE-0.7.md index 3d09f1bc..f4e16b87 100644 --- a/UPGRADE-0.7.md +++ b/UPGRADE-0.7.md @@ -6,7 +6,7 @@ ng-admin 0.7 breaks compatibility with 0.5 and makes the "factories" configurati ## Field type -Method `Field.type()` is no longer supported as a setter. Instead, you should specify the second argument from the field factory. +The `Field.type(type)` method is no longer supported as a setter. Instead, you should specify the type as the second argument in the `nga.field()` factory. ``` diff - nga.field('created_at').type('date') @@ -74,13 +74,16 @@ Adding menu children by hand is also the only way to determine the menu order. The `menuView()` syntax will still be supported in this version, but removed in the next one. -## Passing Literal to `View.fields()` and Using `field.order` Is Deprecated -Prior to 0.7, you could pass both literal and array to the fields methods which returned a literal. Now the fields method return an array. And passing literal to it is deprecated. -Additionaly, the order method which served to order fields passed in literal form is also deprecated. +## Passing Object Literal to `View.fields()` and Using `field.order` Are Deprecated -The proper way to use fields is now by passing field and or arrays of fields. -``` -fields(field1, field2) +Calling `view.fields()` as a getter (with no argument) used to return an object literal ; starting with 0.7, it now returns an array. +Symmetrically, passing an object litteral as argument to the setter methor `view.fields(fields)` is deprecated ; only arrays are now officially supported. + +Additionaly, the `order()` method, which served to order fields passed in object literal form, is also deprecated. + +The proper way to use `fields()` is to pass an array of fields. + +```js fields([field1, field2]) -fields(field1, [field2, field3]) +fields([field1, [field2, field3]]) ``` diff --git a/src/javascripts/ng-admin/es6/tests/lib/View/ViewTest.js b/src/javascripts/ng-admin/es6/tests/lib/View/ViewTest.js index dca4f637..e95bad62 100644 --- a/src/javascripts/ng-admin/es6/tests/lib/View/ViewTest.js +++ b/src/javascripts/ng-admin/es6/tests/lib/View/ViewTest.js @@ -89,6 +89,15 @@ describe('View', function() { assert.deepEqual(view.fields(), [field1, field2]); }); + it('should add fields when called with a nested array argument', function() { + var view = new View(new Entity('post')); + var field1 = new Field('foo'); + var field2 = new Field('bar'); + view.fields([field1, [field2]]); + + assert.deepEqual(view.fields(), [field1, field2]); + }); + it('should add a single field when called with a non array argument', function() { var view = new View(new Entity('post')); var field1 = new Field('foo');