Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit ac9941a

Browse files
committed
docs(cb-a11y): Building examples - Form controls
1 parent 06a5bb2 commit ac9941a

File tree

5 files changed

+87
-28
lines changed

5 files changed

+87
-28
lines changed

public/docs/_examples/cb-a11y/ts/app/a11y-form-controls.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
What do you like most about Angular 2?
1515
</a11y-checkboxes>
1616

17+
<a11y-radiobuttons [radiobuttonModel]="radioButtons" [radiobuttonName]="'language'">
18+
Choose your favourite Angular 2 language:
19+
</a11y-radiobuttons>
20+
1721

1822
<div class="form-group">
1923
<label for="a11yreason">Why are you interested in a11y?

public/docs/_examples/cb-a11y/ts/app/a11y-form-controls.component.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,25 @@ import {CORE_DIRECTIVES, FORM_DIRECTIVES} from "angular2/common";
33
import {A11yInput} from "./a11y-input.component";
44
import {A11yInputExplicit} from "./a11y-input-explicit.component";
55
import {A11yCheckboxes} from "./a11y-checkboxes.component";
6+
import {A11yHelper} from "./services/a11y-helper.service";
7+
import {A11yRadiobuttons} from "./a11y-radiobuttons.component";
68

79
@Component({
810
selector: 'a11y-form-controls',
911
templateUrl: './app/a11y-form-controls.component.html',
10-
directives: [CORE_DIRECTIVES, FORM_DIRECTIVES, A11yInput, A11yInputExplicit, A11yCheckboxes]
12+
directives: [CORE_DIRECTIVES, FORM_DIRECTIVES, A11yInput, A11yInputExplicit, A11yCheckboxes, A11yRadiobuttons]
1113
})
1214
export class A11yFormControls implements OnInit{
1315

1416
checkBoxes: any;
17+
radioButtons: any;
18+
19+
constructor(private _a11yHelper: A11yHelper){
20+
}
1521

1622
ngOnInit(){
17-
this.checkBoxes = [
18-
{
19-
name: 'Template syntax',
20-
value: 0
21-
},
22-
{
23-
name: 'Observables',
24-
value: 1
25-
},
26-
{
27-
name: 'Components',
28-
value: 2
29-
},
30-
{
31-
name: 'Forms',
32-
value: 3
33-
}
34-
];
23+
this.checkBoxes = this._a11yHelper.getCheckboxModel();
24+
this.radioButtons = this._a11yHelper.getRadiobuttonsModel();
3525
}
3626

3727
submit(formValue: any):void{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<fieldset class="form-group row">
2+
<div class="col-xs-12">
3+
<legend><ng-content></ng-content></legend>
4+
<div *ngFor="#radiobutton of radiobuttonModel" class="radio col-xs-12">
5+
<label>
6+
<input type="radio" [value]="radiobutton.value" [name]="radiobuttonName">
7+
{{radiobutton.name}}
8+
</label>
9+
</div>
10+
</div>
11+
</fieldset>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {Input, Component} from "angular2/core";
2+
3+
@Component({
4+
selector: 'a11y-radiobuttons',
5+
templateUrl: './app/a11y-radiobuttons.component.html'
6+
})
7+
export class A11yRadiobuttons {
8+
@Input()
9+
radiobuttonName: string;
10+
@Input()
11+
radiobuttonModel: any;
12+
}

public/docs/_examples/cb-a11y/ts/app/services/a11y-helper.service.ts

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,59 @@ import {Injectable} from "angular2/core";
33
@Injectable()
44
export class A11yHelper {
55
generateUniqueIdString():string {
6-
return (this.randomGuidSnippet() +
7-
this.randomGuidSnippet() + "-" +
8-
this.randomGuidSnippet() + "-4" +
9-
this.randomGuidSnippet().substr(0,3) + "-" +
10-
this.randomGuidSnippet() + "-" +
11-
this.randomGuidSnippet() +
12-
this.randomGuidSnippet() +
6+
return (this.randomGuidSnippet() +
7+
this.randomGuidSnippet() + "-" +
8+
this.randomGuidSnippet() + "-4" +
9+
this.randomGuidSnippet().substr(0, 3) + "-" +
10+
this.randomGuidSnippet() + "-" +
11+
this.randomGuidSnippet() +
12+
this.randomGuidSnippet() +
1313
this.randomGuidSnippet()).toLowerCase();
1414
}
1515

16-
private randomGuidSnippet (): string {
17-
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
16+
getCheckboxModel():any {
17+
return [
18+
{
19+
name: 'Template syntax',
20+
value: 0
21+
},
22+
{
23+
name: 'Observables',
24+
value: 1
25+
},
26+
{
27+
name: 'Components',
28+
value: 2
29+
},
30+
{
31+
name: 'Forms',
32+
value: 3
33+
}
34+
];
35+
}
36+
37+
getRadiobuttonsModel():any {
38+
return [
39+
{
40+
name: 'TypeScript',
41+
value: 0
42+
},
43+
{
44+
name: 'JavaScript',
45+
value: 1
46+
},
47+
{
48+
name: 'ES6',
49+
value: 2
50+
},
51+
{
52+
name: 'Dart',
53+
value: 3
54+
}
55+
];
56+
}
57+
58+
private randomGuidSnippet():string {
59+
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
1860
}
1961
}

0 commit comments

Comments
 (0)