Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 91a34a7

Browse files
committed
remove ng:format=index
1 parent af285dd commit 91a34a7

File tree

5 files changed

+9
-110
lines changed

5 files changed

+9
-110
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- injection name inference no longer supports method curry and linking functions. Both must be
1616
explicitly specified using $inject property.
1717
- Dynamic Iteration (ng:repeater) on <option> elements is no longer supported. Use ng:options
18+
- Removal of index formatter since its only use was with repeated options (see above)
1819

1920

2021

src/formatters.js

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -199,64 +199,3 @@ angularFormatter.list = formatter(
199199
angularFormatter.trim = formatter(
200200
function(obj) { return obj ? trim("" + obj) : ""; }
201201
);
202-
203-
/**
204-
* @workInProgress
205-
* @ngdoc formatter
206-
* @name angular.formatter.index
207-
* @deprecated
208-
* @description
209-
* Index formatter is meant to be used with `select` input widget. It is useful when one needs
210-
* to select from a set of objects. To create pull-down one can iterate over the array of object
211-
* to build the UI. However the value of the pull-down must be a string. This means that when on
212-
* object is selected form the pull-down, the pull-down value is a string which needs to be
213-
* converted back to an object. This conversion from string to on object is not possible, at best
214-
* the converted object is a copy of the original object. To solve this issue we create a pull-down
215-
* where the value strings are an index of the object in the array. When pull-down is selected the
216-
* index can be used to look up the original user object.
217-
*
218-
* @inputType select
219-
* @param {array} array to be used for selecting an object.
220-
* @returns {object} object which is located at the selected position.
221-
*
222-
* @example
223-
<doc:example>
224-
<doc:source>
225-
<script>
226-
function DemoCntl(){
227-
this.users = [
228-
{name:'guest', password:'guest'},
229-
{name:'user', password:'123'},
230-
{name:'admin', password:'abc'}
231-
];
232-
}
233-
</script>
234-
<div ng:controller="DemoCntl">
235-
User:
236-
<select name="currentUser" ng:format="index:users">
237-
<option ng:repeat="user in users" value="{{$index}}">{{user.name}}</option>
238-
</select>
239-
<select name="currentUser" ng:format="index:users">
240-
<option ng:repeat="user in users" value="{{$index}}">{{user.name}}</option>
241-
</select>
242-
user={{currentUser.name}}<br/>
243-
password={{currentUser.password}}<br/>
244-
</doc:source>
245-
<doc:scenario>
246-
it('should retrieve object by index', function(){
247-
expect(binding('currentUser.password')).toEqual('guest');
248-
select('currentUser').option('2');
249-
expect(binding('currentUser.password')).toEqual('abc');
250-
});
251-
</doc:scenario>
252-
</doc:example>
253-
*/
254-
//TODO: delete me since this is replaced by ng:options
255-
angularFormatter.index = formatter(
256-
function(object, array){
257-
return '' + indexOf(array || [], object);
258-
},
259-
function(index, array){
260-
return (array||[])[index];
261-
}
262-
);

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 & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -395,43 +395,6 @@ describe("widget", function(){
395395
scope.$eval();
396396
expect(element[0].childNodes[0].selected).toEqual(true);
397397
});
398-
399-
it('should allow binding to objects through index', function(){
400-
compile('<div ng:init="list = [{name:\'A\'}, {name:\'B\'}, {name:\'C\'}]">' +
401-
'<select name="selection" multiple ng:format="index:list">' +
402-
'<option selected value="0">A</option>' +
403-
'<option selected value="1">B</option>' +
404-
'<option value="2">C</option>' +
405-
'</select>' +
406-
'</div>');
407-
scope.$eval();
408-
expect(scope.selection).toEqual([{name:'A'}, {name:'B'}]);
409-
});
410-
411-
it('should be empty array when no items are selected', function(){
412-
compile(
413-
'<select name="selection" multiple ng:format="index:list">' +
414-
'<option value="0">A</option>' +
415-
'<option value="1">B</option>' +
416-
'<option value="2">C</option>' +
417-
'</select>');
418-
scope.list = [{name:'A'}, {name:'B'}, {name:'C'}];
419-
scope.$eval();
420-
expect(scope.selection).toEqual([]);
421-
});
422-
423-
it('should be contain the selected object', function(){
424-
compile('<div ng:init="list = [{name:\'A\'}, {name:\'B\'}, {name:\'C\'}]">' +
425-
'<select name="selection" multiple ng:format="index:list">' +
426-
'<option value="0">A</option>' +
427-
'<option value="1" selected>B</option>' +
428-
'<option value="2">C</option>' +
429-
'</select>' +
430-
'</div>');
431-
scope.$eval();
432-
expect(scope.selection).toEqual([{name:'B'}]);
433-
});
434-
435398
});
436399

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

0 commit comments

Comments
 (0)