Skip to content

Commit e6ee994

Browse files
Di PengIgorMinar
Di Peng
authored andcommitted
Added ng:disabled, ng:checked, ng:multiple, ng:readonly, ng:selected to markup.js.
Also added coresponding descriptions live examples and tests for each directive to be displayed on the website. Closes angular#351
1 parent c8ee00c commit e6ee994

File tree

4 files changed

+216
-1
lines changed

4 files changed

+216
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
### New Features
55
- Added prepend() to jqLite
66
- Added ng:options directive (http://docs.angularjs.org/#!angular.directive.ng:options)
7+
- Added ng:disabled, ng:selected, ng:checked, ng:multiple, ng:readonly directive.
78

89

910
### Bug Fixes

src/directives.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ var REMOVE_ATTRIBUTES = {
384384
'disabled':'disabled',
385385
'readonly':'readOnly',
386386
'checked':'checked',
387-
'selected':'selected'
387+
'selected':'selected',
388+
'multiple':'multiple'
388389
};
389390
/**
390391
* @workInProgress

src/markups.js

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,171 @@ angularTextMarkup('option', function(text, textNode, parentElement){
235235
* @param {template} template any string which can contain `{{}}` markup.
236236
*/
237237

238+
/**
239+
* @workInProgress
240+
* @ngdoc directive
241+
* @name angular.directive.ng:disabled
242+
*
243+
* @description
244+
*
245+
* The following markup will make the button enabled on Chrome/Firefox but not on IE8 and older IEs:
246+
* <pre>
247+
* <div ng:init="scope = { isDisabled: false }">
248+
* <button disabled="{{scope.isDisabled}}">Disabled</button>
249+
* </div>
250+
* </pre>
251+
*
252+
* the HTML specs do not require browsers preserve the special attributes such as disabled.(The presense of them means true and absense means false)
253+
* This prevents the angular compiler from correctly retrieving the binding expression.
254+
* To solve this problem, we introduce ng:disabled.
255+
*
256+
* @example
257+
<doc:example>
258+
<doc:source>
259+
Click me to toggle: <input type="checkbox" name="checked"><br/>
260+
<button name="button" ng:disabled="{{checked}}">Button</button>
261+
</doc:source>
262+
<doc:scenario>
263+
it('should toggle button', function() {
264+
expect(element('.doc-example-live :button').attr('disabled')).toBeFalsy();
265+
input('checked').check();
266+
expect(element('.doc-example-live :button').attr('disabled')).toBeTruthy();
267+
});
268+
</doc:scenario>
269+
</doc:example>
270+
*
271+
* @element ANY
272+
* @param {template} template any string which can contain '{{}}' markup.
273+
*/
274+
275+
276+
/**
277+
* @workInProgress
278+
* @ngdoc directive
279+
* @name angular.directive.ng:checked
280+
*
281+
* @description
282+
* the HTML specs do not require browsers preserve the special attributes such as checked.(The presense of them means true and absense means false)
283+
* This prevents the angular compiler from correctly retrieving the binding expression.
284+
* To solve this problem, we introduce ng:checked.
285+
* @example
286+
<doc:example>
287+
<doc:source>
288+
Check me to check both: <input type="checkbox" name="master"><br/>
289+
<input id="checkSlave" type="checkbox" ng:checked="{{master}}">
290+
</doc:source>
291+
<doc:scenario>
292+
it('should check both checkBoxes', function() {
293+
expect(element('.doc-example-live #checkSlave').attr('checked')).toBeFalsy();
294+
input('master').check();
295+
expect(element('.doc-example-live #checkSlave').attr('checked')).toBeTruthy();
296+
});
297+
</doc:scenario>
298+
</doc:example>
299+
*
300+
* @element ANY
301+
* @param {template} template any string which can contain '{{}}' markup.
302+
*/
303+
304+
305+
/**
306+
* @workInProgress
307+
* @ngdoc directive
308+
* @name angular.directive.ng:multiple
309+
*
310+
* @description
311+
* the HTML specs do not require browsers preserve the special attributes such as multiple.(The presense of them means true and absense means false)
312+
* This prevents the angular compiler from correctly retrieving the binding expression.
313+
* To solve this problem, we introduce ng:multiple.
314+
*
315+
* @example
316+
<doc:example>
317+
<doc:source>
318+
Check me check multiple: <input type="checkbox" name="checked"><br/>
319+
<select id="select" ng:multiple="{{checked}}">
320+
<option>Misko</option>
321+
<option>Igor</option>
322+
<option>Vojita</option>
323+
<option>Di</option>
324+
</select>
325+
</doc:source>
326+
<doc:scenario>
327+
it('should toggle multiple', function() {
328+
expect(element('.doc-example-live #select').attr('multiple')).toBeFalsy();
329+
input('checked').check();
330+
expect(element('.doc-example-live #select').attr('multiple')).toBeTruthy();
331+
});
332+
</doc:scenario>
333+
</doc:example>
334+
*
335+
* @element ANY
336+
* @param {template} template any string which can contain '{{}}' markup.
337+
*/
338+
339+
340+
/**
341+
* @workInProgress
342+
* @ngdoc directive
343+
* @name angular.directive.ng:readonly
344+
*
345+
* @description
346+
* the HTML specs do not require browsers preserve the special attributes such as readonly.(The presense of them means true and absense means false)
347+
* This prevents the angular compiler from correctly retrieving the binding expression.
348+
* To solve this problem, we introduce ng:readonly.
349+
* @example
350+
<doc:example>
351+
<doc:source>
352+
Check me to make text readonly: <input type="checkbox" name="checked"><br/>
353+
<input type="text" ng:readonly="{{checked}}" value="I'm Angular"/>
354+
</doc:source>
355+
<doc:scenario>
356+
it('should toggle readonly attr', function() {
357+
expect(element('.doc-example-live :text').attr('readonly')).toBeFalsy();
358+
input('checked').check();
359+
expect(element('.doc-example-live :text').attr('readonly')).toBeTruthy();
360+
});
361+
</doc:scenario>
362+
</doc:example>
363+
*
364+
* @element ANY
365+
* @param {template} template any string which can contain '{{}}' markup.
366+
*/
367+
368+
369+
/**
370+
* @workInProgress
371+
* @ngdoc directive
372+
* @name angular.directive.ng:selected
373+
*
374+
* @description
375+
* the HTML specs do not require browsers preserve the special attributes such as selected.(The presense of them means true and absense means false)
376+
* This prevents the angular compiler from correctly retrieving the binding expression.
377+
* To solve this problem, we introduce ng:selected.
378+
* @example
379+
<doc:example>
380+
<doc:source>
381+
Check me to select: <input type="checkbox" name="checked"><br/>
382+
<select>
383+
<option>Hello!</option>
384+
<option id="greet" ng:selected="{{checked}}">Greetings!</option>
385+
</select>
386+
</doc:source>
387+
<doc:scenario>
388+
it('should select Greetings!', function() {
389+
expect(element('.doc-example-live #greet').attr('selected')).toBeFalsy();
390+
input('checked').check();
391+
expect(element('.doc-example-live #greet').attr('selected')).toBeTruthy();
392+
});
393+
</doc:scenario>
394+
</doc:example>
395+
* @element ANY
396+
* @param {template} template any string which can contain '{{}}' markup.
397+
*/
398+
399+
238400
var NG_BIND_ATTR = 'ng:bind-attr';
239401
var SPECIAL_ATTRS = {};
402+
240403
forEach('src,href,checked,disabled,multiple,readonly,selected'.split(','), function(name) {
241404
SPECIAL_ATTRS['ng:' + name] = name;
242405
});

test/markupSpec.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,56 @@ describe("markups", function(){
8989
expect(sortedHtml(element)).toEqual('<a ng:bind-attr="{"href":"{{url}}"}"></a>');
9090
});
9191

92+
it('should bind disabled', function() {
93+
compile('<button ng:disabled="{{isDisabled}}">Button</button>');
94+
scope.isDisabled = false;
95+
scope.$eval();
96+
expect(element.attr('disabled')).toBeFalsy();
97+
scope.isDisabled = true;
98+
scope.$eval();
99+
expect(element.attr('disabled')).toBeTruthy();
100+
});
101+
102+
it('should bind checked', function() {
103+
compile('<input type="checkbox" ng:checked="{{isChecked}}" />');
104+
scope.isChecked = false;
105+
scope.$eval();
106+
expect(element.attr('checked')).toBeFalsy();
107+
scope.isChecked=true;
108+
scope.$eval();
109+
expect(element.attr('checked')).toBeTruthy();
110+
});
111+
112+
it('should bind selected', function() {
113+
compile('<select><option value=""></option><option ng:selected="{{isSelected}}">Greetings!</option></select>');
114+
scope.isSelected=false;
115+
scope.$eval();
116+
expect(element.children()[1].selected).toBeFalsy();
117+
scope.isSelected=true;
118+
scope.$eval();
119+
expect(element.children()[1].selected).toBeTruthy();
120+
});
121+
122+
it('should bind readonly', function() {
123+
compile('<input type="text" ng:readonly="{{isReadonly}}" />');
124+
scope.isReadonly=false;
125+
scope.$eval();
126+
expect(element.attr('readOnly')).toBeFalsy();
127+
scope.isReadonly=true;
128+
scope.$eval();
129+
expect(element.attr('readOnly')).toBeTruthy();
130+
});
131+
132+
it('should bind multiple', function() {
133+
compile('<select ng:multiple="{{isMultiple}}"></select>');
134+
scope.isMultiple=false;
135+
scope.$eval();
136+
expect(element.attr('multiple')).toBeFalsy();
137+
scope.isMultiple='multiple';
138+
scope.$eval();
139+
expect(element.attr('multiple')).toBeTruthy();
140+
});
141+
92142
it('should bind src', function() {
93143
compile('<img ng:src="{{url}}" />');
94144
scope.url = 'http://localhost/';

0 commit comments

Comments
 (0)