-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(buttons): fix radio btns for reactive forms, add radio reactive demo #3384
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
64c87cf
fix(buttons): fix radio btns for reactive forms, add radio reactive demo
IlyaSurmay a7c3173
Merge branch 'development' into fix-radio-reactive
IlyaSurmay 1ba14cb
feat(buttons): add setDisabledState
IlyaSurmay 9b9f21f
Merge branch 'development' into fix-radio-reactive
valorkin 3c2d5b4
Merge branch 'development' into fix-radio-reactive
valorkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
demo/src/app/components/+buttons/demos/checkbox-reactiveforms/checkbox-reactiveforms.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<pre class="card card-block card-header">{{myForm.value | json}}</pre> | ||
<form [formGroup]="myForm"> | ||
<div class="btn-group"> | ||
<label class="btn btn-primary" [class.active]="myForm.value.left" | ||
btnCheckbox formControlName="left">Left</label> | ||
|
||
<label class="btn btn-primary" [class.active]="myForm.value.middle" | ||
btnCheckbox formControlName="middle">Middle</label> | ||
|
||
<label class="btn btn-primary" [class.active]="myForm.value.right" | ||
btnCheckbox formControlName="right">Right</label> | ||
</div> | ||
</form> |
20 changes: 20 additions & 0 deletions
20
demo/src/app/components/+buttons/demos/checkbox-reactiveforms/checkbox-reactiveforms.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { FormBuilder, FormGroup } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'demo-buttons-checkbox-reactiveforms', | ||
templateUrl: './checkbox-reactiveforms.html' | ||
}) | ||
export class DemoButtonsCheckboxReactiveFormsComponent implements OnInit { | ||
myForm: FormGroup; | ||
|
||
constructor(private formBuilder: FormBuilder) {} | ||
|
||
ngOnInit() { | ||
this.myForm = this.formBuilder.group({ | ||
left: false, | ||
middle: true, | ||
right: false | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import { DemoButtonsBasicComponent } from './basic/basic'; | ||
import { DemoButtonsCheckboxComponent } from './checkbox/checkbox'; | ||
import { DemoButtonsRadioComponent } from './radio/radio'; | ||
import { DemoButtonsRadioReactiveFormsComponent } from './radio-reactiveforms/radio-reactiveforms'; | ||
import { DemoButtonsCheckboxReactiveFormsComponent } from './checkbox-reactiveforms/checkbox-reactiveforms'; | ||
import { DemoButtonsDisabledComponent } from './disabled/disabled'; | ||
import { DemoButtonsRadioReactiveFormsComponent } from './radio-reactiveforms/radio-reactiveforms'; | ||
|
||
export const DEMO_COMPONENTS = [ | ||
DemoButtonsBasicComponent, | ||
DemoButtonsCheckboxComponent, | ||
DemoButtonsRadioComponent, | ||
DemoButtonsCheckboxReactiveFormsComponent, | ||
DemoButtonsRadioReactiveFormsComponent, | ||
DemoButtonsDisabledComponent | ||
]; |
19 changes: 8 additions & 11 deletions
19
demo/src/app/components/+buttons/demos/radio-reactiveforms/radio-reactiveforms.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
<pre class="card card-block card-header">{{myForm.value | json}}</pre> | ||
<form [formGroup]="myForm"> | ||
<div class="btn-group"> | ||
<label class="btn btn-primary" [class.active]="myForm.value.left" | ||
btnCheckbox formControlName="left">Left</label> | ||
|
||
<label class="btn btn-primary" [class.active]="myForm.value.middle" | ||
btnCheckbox formControlName="middle">Middle</label> | ||
|
||
<label class="btn btn-primary" [class.active]="myForm.value.right" | ||
btnCheckbox formControlName="right">Right</label> | ||
<pre class="card card-block card-header">{{ myForm.value | json }}</pre> | ||
<form [formGroup]="myForm" class="form-inline"> | ||
<div class="form-group"> | ||
<div class="btn-group" btnRadioGroup formControlName="radio"> | ||
<label btnRadio="A" class="btn btn-primary">A</label> | ||
<label btnRadio="B" class="btn btn-primary">B</label> | ||
<label btnRadio="C" class="btn btn-primary">C</label> | ||
</div> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// tslint:disable:no-use-before-declare | ||
import { ChangeDetectorRef, Directive, ElementRef, forwardRef, Input } from '@angular/core'; | ||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | ||
|
||
export const RADIO_CONTROL_VALUE_ACCESSOR: any = { | ||
provide: NG_VALUE_ACCESSOR, | ||
useExisting: forwardRef(() => ButtonRadioGroupDirective), | ||
multi: true | ||
}; | ||
|
||
/** | ||
* A group of radio buttons. | ||
* A value of a selected button is bound to a variable specified via ngModel. | ||
*/ | ||
@Directive({ | ||
selector: '[btnRadioGroup]', | ||
providers: [RADIO_CONTROL_VALUE_ACCESSOR] | ||
}) | ||
export class ButtonRadioGroupDirective implements ControlValueAccessor { | ||
onChange: any = Function.prototype; | ||
onTouched: any = Function.prototype; | ||
|
||
get value(): any { | ||
return this._value; | ||
} | ||
set value(value: any) { | ||
this._value = value; | ||
} | ||
|
||
private _value: any; | ||
|
||
constructor(private el: ElementRef, private cdr: ChangeDetectorRef) {} | ||
|
||
writeValue(value: any): void { | ||
this._value = value; | ||
this.cdr.markForCheck(); | ||
} | ||
|
||
registerOnChange(fn: any): void { | ||
this.onChange = fn; | ||
} | ||
|
||
registerOnTouched(fn: any): void { | ||
this.onTouched = fn; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { ButtonCheckboxDirective } from './button-checkbox.directive'; | ||
export { ButtonRadioGroupDirective } from './button-radio-group.directive'; | ||
export { ButtonRadioDirective } from './button-radio.directive'; | ||
export { ButtonsModule } from './buttons.module'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as off-topic.
Sorry, something went wrong.