Skip to content

Commit f8ed354

Browse files
authored
fix(material,bootstrap): Add asterisk for checkbox. (#624)
fix #623
1 parent 46ae9e0 commit f8ed354

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

demo/src/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@import '~bootstrap/scss/root';
66
@import '~bootstrap/scss/buttons';
77
@import '~bootstrap/scss/forms';
8+
@import '~bootstrap/scss/custom-forms';
89
@import '~bootstrap/scss/card';
910

1011
// prism
Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
import { Component } from '@angular/core';
2-
import { FormControl, AbstractControl } from '@angular/forms';
3-
import { FieldType, FormlyFieldConfig } from '@ngx-formly/core';
2+
import { FieldType } from '@ngx-formly/core';
43

54
@Component({
65
selector: 'formly-field-checkbox',
76
template: `
87
<label class="custom-control custom-checkbox">
98
<input type="checkbox" [formControl]="formControl"
10-
*ngIf="!to.hidden" value="on"
9+
[attr.invalid]="showError"
10+
[indeterminate]="model[id] === undefined"
1111
[formlyAttributes]="field" class="custom-control-input">
1212
{{ to.label }}
13+
{{ to.required ? '*' : '' }}
1314
<span class="custom-control-indicator"></span>
1415
</label>
1516
`,
1617
})
17-
export class FormlyFieldCheckbox extends FieldType {
18-
static createControl(model: any, field: FormlyFieldConfig): AbstractControl {
19-
return new FormControl(
20-
{ value: model ? 'on' : undefined, disabled: field.templateOptions.disabled },
21-
field.validators ? field.validators.validation : undefined,
22-
field.asyncValidators ? field.asyncValidators.validation : undefined,
23-
);
24-
}
25-
}
18+
export class FormlyFieldCheckbox extends FieldType {}

src/ui-material/src/types/checkbox.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { MatCheckbox } from '@angular/material/checkbox';
55
@Component({
66
selector: 'formly-field-mat-checkbox',
77
template: `
8-
<mat-checkbox [formControl]="formControl" [id]="id" [formlyAttributes]="field">{{ to.label }}</mat-checkbox>
8+
<mat-checkbox [formControl]="formControl" [id]="id" [formlyAttributes]="field">
9+
{{ to.label }}
10+
{{ to.required ? '*' : '' }}
11+
</mat-checkbox>
912
`,
1013
})
1114
export class FormlyFieldCheckbox extends FieldType implements AfterViewInit {

0 commit comments

Comments
 (0)