mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
remove ng:format=index
This commit is contained in:
parent
af285dd370
commit
91a34a7027
5 changed files with 9 additions and 110 deletions
|
|
@ -15,6 +15,7 @@
|
|||
- injection name inference no longer supports method curry and linking functions. Both must be
|
||||
explicitly specified using $inject property.
|
||||
- Dynamic Iteration (ng:repeater) on <option> elements is no longer supported. Use ng:options
|
||||
- Removal of index formatter since its only use was with repeated options (see above)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -199,64 +199,3 @@ angularFormatter.list = formatter(
|
|||
angularFormatter.trim = formatter(
|
||||
function(obj) { return obj ? trim("" + obj) : ""; }
|
||||
);
|
||||
|
||||
/**
|
||||
* @workInProgress
|
||||
* @ngdoc formatter
|
||||
* @name angular.formatter.index
|
||||
* @deprecated
|
||||
* @description
|
||||
* Index formatter is meant to be used with `select` input widget. It is useful when one needs
|
||||
* to select from a set of objects. To create pull-down one can iterate over the array of object
|
||||
* to build the UI. However the value of the pull-down must be a string. This means that when on
|
||||
* object is selected form the pull-down, the pull-down value is a string which needs to be
|
||||
* converted back to an object. This conversion from string to on object is not possible, at best
|
||||
* the converted object is a copy of the original object. To solve this issue we create a pull-down
|
||||
* where the value strings are an index of the object in the array. When pull-down is selected the
|
||||
* index can be used to look up the original user object.
|
||||
*
|
||||
* @inputType select
|
||||
* @param {array} array to be used for selecting an object.
|
||||
* @returns {object} object which is located at the selected position.
|
||||
*
|
||||
* @example
|
||||
<doc:example>
|
||||
<doc:source>
|
||||
<script>
|
||||
function DemoCntl(){
|
||||
this.users = [
|
||||
{name:'guest', password:'guest'},
|
||||
{name:'user', password:'123'},
|
||||
{name:'admin', password:'abc'}
|
||||
];
|
||||
}
|
||||
</script>
|
||||
<div ng:controller="DemoCntl">
|
||||
User:
|
||||
<select name="currentUser" ng:format="index:users">
|
||||
<option ng:repeat="user in users" value="{{$index}}">{{user.name}}</option>
|
||||
</select>
|
||||
<select name="currentUser" ng:format="index:users">
|
||||
<option ng:repeat="user in users" value="{{$index}}">{{user.name}}</option>
|
||||
</select>
|
||||
user={{currentUser.name}}<br/>
|
||||
password={{currentUser.password}}<br/>
|
||||
</doc:source>
|
||||
<doc:scenario>
|
||||
it('should retrieve object by index', function(){
|
||||
expect(binding('currentUser.password')).toEqual('guest');
|
||||
select('currentUser').option('2');
|
||||
expect(binding('currentUser.password')).toEqual('abc');
|
||||
});
|
||||
</doc:scenario>
|
||||
</doc:example>
|
||||
*/
|
||||
//TODO: delete me since this is replaced by ng:options
|
||||
angularFormatter.index = formatter(
|
||||
function(object, array){
|
||||
return '' + indexOf(array || [], object);
|
||||
},
|
||||
function(index, array){
|
||||
return (array||[])[index];
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -40,13 +40,4 @@ describe("formatter", function(){
|
|||
});
|
||||
});
|
||||
|
||||
describe('index', function(){
|
||||
it('should parse an object from array', function(){
|
||||
expect(angular.formatter.index.parse('1', ['A', 'B', 'C'])).toEqual('B');
|
||||
});
|
||||
it('should format an index from array', function(){
|
||||
expect(angular.formatter.index.format('B', ['A', 'B', 'C'])).toEqual('1');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -405,9 +405,14 @@ describe('parser', function() {
|
|||
});
|
||||
|
||||
it('should delegate arguments', function(){
|
||||
var index = parser('index:objs').formatter()();
|
||||
expect(index.format({objs:['A','B']}, 'B')).toEqual('1');
|
||||
expect(index.parse({objs:['A','B']}, '1')).toEqual('B');
|
||||
angularFormatter.myArgs = {
|
||||
parse: function(a, b){ return [a, b]; },
|
||||
format: function(a, b){ return [a, b]; }
|
||||
};
|
||||
var myArgs = parser('myArgs:objs').formatter()();
|
||||
expect(myArgs.format({objs:'B'}, 'A')).toEqual(['A', 'B']);
|
||||
expect(myArgs.parse({objs:'D'}, 'C')).toEqual(['C', 'D']);
|
||||
delete angularFormatter.myArgs;
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -395,43 +395,6 @@ describe("widget", function(){
|
|||
scope.$eval();
|
||||
expect(element[0].childNodes[0].selected).toEqual(true);
|
||||
});
|
||||
|
||||
it('should allow binding to objects through index', function(){
|
||||
compile('<div ng:init="list = [{name:\'A\'}, {name:\'B\'}, {name:\'C\'}]">' +
|
||||
'<select name="selection" multiple ng:format="index:list">' +
|
||||
'<option selected value="0">A</option>' +
|
||||
'<option selected value="1">B</option>' +
|
||||
'<option value="2">C</option>' +
|
||||
'</select>' +
|
||||
'</div>');
|
||||
scope.$eval();
|
||||
expect(scope.selection).toEqual([{name:'A'}, {name:'B'}]);
|
||||
});
|
||||
|
||||
it('should be empty array when no items are selected', function(){
|
||||
compile(
|
||||
'<select name="selection" multiple ng:format="index:list">' +
|
||||
'<option value="0">A</option>' +
|
||||
'<option value="1">B</option>' +
|
||||
'<option value="2">C</option>' +
|
||||
'</select>');
|
||||
scope.list = [{name:'A'}, {name:'B'}, {name:'C'}];
|
||||
scope.$eval();
|
||||
expect(scope.selection).toEqual([]);
|
||||
});
|
||||
|
||||
it('should be contain the selected object', function(){
|
||||
compile('<div ng:init="list = [{name:\'A\'}, {name:\'B\'}, {name:\'C\'}]">' +
|
||||
'<select name="selection" multiple ng:format="index:list">' +
|
||||
'<option value="0">A</option>' +
|
||||
'<option value="1" selected>B</option>' +
|
||||
'<option value="2">C</option>' +
|
||||
'</select>' +
|
||||
'</div>');
|
||||
scope.$eval();
|
||||
expect(scope.selection).toEqual([{name:'B'}]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should ignore text widget which have no name', function(){
|
||||
|
|
|
|||
Loading…
Reference in a new issue