diff options
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | src/formatters.js | 61 | ||||
| -rw-r--r-- | test/FormattersSpec.js | 9 | ||||
| -rw-r--r-- | test/ParserSpec.js | 11 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 37 |
5 files changed, 9 insertions, 110 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 83aaa8c7..6c8672ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/formatters.js b/src/formatters.js index b484f26f..3eb71bfd 100644 --- a/src/formatters.js +++ b/src/formatters.js @@ -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]; - } -); diff --git a/test/FormattersSpec.js b/test/FormattersSpec.js index 234a81d6..1e059e6a 100644 --- a/test/FormattersSpec.js +++ b/test/FormattersSpec.js @@ -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'); - }); - }); - }); diff --git a/test/ParserSpec.js b/test/ParserSpec.js index 641420cb..d2a1c5ba 100644 --- a/test/ParserSpec.js +++ b/test/ParserSpec.js @@ -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; }); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 176f6b9c..d3b2ec5d 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -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(){ |
