Skip to content

Commit

Permalink
Merge pull request #394 from marmelab/fix_order_bug
Browse files Browse the repository at this point in the history
[RFR] fix ordering when more than 10 fields
  • Loading branch information
fzaninotto committed Apr 13, 2015
2 parents eee2e1f + 3b5909c commit 618bd9c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/javascripts/ng-admin/es6/lib/Field/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ class Field {
}

order() {
if (arguments.length && arguments[1] !== true) {
console.warn('Setting order with Field.order is deprecated, order directly in fields array');
if (arguments.length) {
if(arguments[1] !== true) {
console.warn('Setting order with Field.order is deprecated, order directly in fields array');
}
this._order = arguments[0];
return this;
}

return this._order || 0;
return this._order;
}

isDetailLink(detailLink) {
Expand Down
14 changes: 14 additions & 0 deletions src/javascripts/ng-admin/es6/tests/lib/View/ViewTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ describe('View', function() {
assert.deepEqual(view.fields(), [field1, field2]);
});

it('should keep the default order of the given array to equal to the index even when more than 10 fields', function() {
var view = new View(new Entity('post'));
var fields = Array.from(new Array(11).keys()).map(function (i) {
return new Field(i);
});
view.fields(fields);

assert.deepEqual(view.fields(), fields);

fields.map(function (field, index) {
assert.equal(field.order(), index);
});
});

it('should add fields when called with a nested array argument', function() {
var view = new View(new Entity('post'));
var field1 = new Field('foo');
Expand Down

0 comments on commit 618bd9c

Please sign in to comment.