Skip to content

Commit e87d58c

Browse files
committed
remove ng:format=index
1 parent 2ba2225 commit e87d58c

File tree

5 files changed

+9
-109
lines changed

5 files changed

+9
-109
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Breaking changes
88
- Dynamic Iteration (ng:repeater) on <option> elements is no longer supported. Use ng:options
9+
- Removal of index formatter since its only use was with repeated options (see above)
910
- $service now has $service.invoke for method injection ($service(self, fn) no longer works)
1011
- injection name inference no longer supports method curry and linking functions. Both must be
1112
explicitly specified using $inject property.

src/formatters.js

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -176,64 +176,3 @@ angularFormatter.list = formatter(
176176
angularFormatter.trim = formatter(
177177
function(obj) { return obj ? trim("" + obj) : ""; }
178178
);
179-
180-
/**
181-
* @workInProgress
182-
* @ngdoc formatter
183-
* @name angular.formatter.index
184-
* @deprecated
185-
* @description
186-
* Index formatter is meant to be used with `select` input widget. It is useful when one needs
187-
* to select from a set of objects. To create pull-down one can iterate over the array of object
188-
* to build the UI. However the value of the pull-down must be a string. This means that when on
189-
* object is selected form the pull-down, the pull-down value is a string which needs to be
190-
* converted back to an object. This conversion from string to on object is not possible, at best
191-
* the converted object is a copy of the original object. To solve this issue we create a pull-down
192-
* where the value strings are an index of the object in the array. When pull-down is selected the
193-
* index can be used to look up the original user object.
194-
*
195-
* @inputType select
196-
* @param {array} array to be used for selecting an object.
197-
* @returns {object} object which is located at the selected position.
198-
*
199-
* @example
200-
<doc:example>
201-
<doc:source>
202-
<script>
203-
function DemoCntl(){
204-
this.users = [
205-
{name:'guest', password:'guest'},
206-
{name:'user', password:'123'},
207-
{name:'admin', password:'abc'}
208-
];
209-
}
210-
</script>
211-
<div ng:controller="DemoCntl">
212-
User:
213-
<select name="currentUser" ng:format="index:users">
214-
<option ng:repeat="user in users" value="{{$index}}">{{user.name}}</option>
215-
</select>
216-
<select name="currentUser" ng:format="index:users">
217-
<option ng:repeat="user in users" value="{{$index}}">{{user.name}}</option>
218-
</select>
219-
user={{currentUser.name}}<br/>
220-
password={{currentUser.password}}<br/>
221-
</doc:source>
222-
<doc:scenario>
223-
it('should retrieve object by index', function(){
224-
expect(binding('currentUser.password')).toEqual('guest');
225-
select('currentUser').option('2');
226-
expect(binding('currentUser.password')).toEqual('abc');
227-
});
228-
</doc:scenario>
229-
</doc:example>
230-
*/
231-
//TODO: delete me since this is replaced by ng:options
232-
angularFormatter.index = formatter(
233-
function(object, array){
234-
return '' + indexOf(array || [], object);
235-
},
236-
function(index, array){
237-
return (array||[])[index];
238-
}
239-
);

test/FormattersSpec.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,4 @@ describe("formatter", function(){
4040
});
4141
});
4242

43-
describe('index', function(){
44-
it('should parse an object from array', function(){
45-
expect(angular.formatter.index.parse('1', ['A', 'B', 'C'])).toEqual('B');
46-
});
47-
it('should format an index from array', function(){
48-
expect(angular.formatter.index.format('B', ['A', 'B', 'C'])).toEqual('1');
49-
});
50-
});
51-
5243
});

test/ParserSpec.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,14 @@ describe('parser', function() {
405405
});
406406

407407
it('should delegate arguments', function(){
408-
var index = parser('index:objs').formatter()();
409-
expect(index.format({objs:['A','B']}, 'B')).toEqual('1');
410-
expect(index.parse({objs:['A','B']}, '1')).toEqual('B');
408+
angularFormatter.myArgs = {
409+
parse: function(a, b){ return [a, b]; },
410+
format: function(a, b){ return [a, b]; }
411+
};
412+
var myArgs = parser('myArgs:objs').formatter()();
413+
expect(myArgs.format({objs:'B'}, 'A')).toEqual(['A', 'B']);
414+
expect(myArgs.parse({objs:'D'}, 'C')).toEqual(['C', 'D']);
415+
delete angularFormatter.myArgs;
411416
});
412417
});
413418

test/widgetsSpec.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -397,42 +397,6 @@ describe("widget", function(){
397397
expect(element[0].childNodes[0].selected).toEqual(true);
398398
});
399399

400-
it('should allow binding to objects through index', function(){
401-
compile('<div ng:init="list = [{name:\'A\'}, {name:\'B\'}, {name:\'C\'}]">' +
402-
'<select name="selection" multiple ng:format="index:list">' +
403-
'<option selected value="0">A</option>' +
404-
'<option selected value="1">B</option>' +
405-
'<option value="2">C</option>' +
406-
'</select>' +
407-
'</div>');
408-
scope.$digest();
409-
expect(scope.selection).toEqual([{name:'A'}, {name:'B'}]);
410-
});
411-
412-
it('should be empty array when no items are selected', function(){
413-
compile(
414-
'<select name="selection" multiple ng:format="index:list">' +
415-
'<option value="0">A</option>' +
416-
'<option value="1">B</option>' +
417-
'<option value="2">C</option>' +
418-
'</select>');
419-
scope.list = [{name:'A'}, {name:'B'}, {name:'C'}];
420-
scope.$digest();
421-
expect(scope.selection).toEqual([]);
422-
});
423-
424-
it('should be contain the selected object', function(){
425-
compile('<div ng:init="list = [{name:\'A\'}, {name:\'B\'}, {name:\'C\'}]">' +
426-
'<select name="selection" multiple ng:format="index:list">' +
427-
'<option value="0">A</option>' +
428-
'<option value="1" selected>B</option>' +
429-
'<option value="2">C</option>' +
430-
'</select>' +
431-
'</div>');
432-
scope.$digest();
433-
expect(scope.selection).toEqual([{name:'B'}]);
434-
});
435-
436400
});
437401

438402
it('should ignore text widget which have no name', function(){

0 commit comments

Comments
 (0)