Skip to content

Commit

Permalink
Adding checkbox component
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jul 2, 2018
1 parent eea081e commit f3b97a7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ui/src/app/schema-form/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { RangeWidget } from 'ngx-schema-form';
import { TextAreaWidget } from 'ngx-schema-form';
import { CustomSelectComponent } from './widget/select/select.component';
import { DatalistComponent } from './widget/datalist/datalist.component';
import { CustomCheckboxComponent } from './widget/check/checkbox.component';


export class CustomWidgetRegistry extends WidgetRegistry {
Expand All @@ -37,6 +38,8 @@ export class CustomWidgetRegistry extends WidgetRegistry {
this.register('fieldset', FieldsetComponent);

this.register('select', CustomSelectComponent);
this.register('boolean', CustomCheckboxComponent);
this.register('checkbox', CustomCheckboxComponent);

this.register('datalist', DatalistComponent);

Expand All @@ -52,8 +55,6 @@ export class CustomWidgetRegistry extends WidgetRegistry {

this.register('file', FileWidget);
this.register('radio', RadioWidget);
this.register('boolean', CheckboxWidget);
this.register('checkbox', CheckboxWidget);

this.register('button', ButtonWidget);

Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/schema-form/schema-form.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import { NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap';
import { SharedModule } from '../shared/shared.module';
import { CustomSelectComponent } from './widget/select/select.component';
import { DatalistComponent } from './widget/datalist/datalist.component';
import { CustomCheckboxComponent } from './widget/check/checkbox.component';

export const COMPONENTS = [
BooleanRadioComponent,
FieldsetComponent,
CustomStringComponent,
CustomSelectComponent,
DatalistComponent
DatalistComponent,
CustomCheckboxComponent
];

@NgModule({
Expand Down
28 changes: 28 additions & 0 deletions ui/src/app/schema-form/widget/check/checkbox.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div class="widget form-group">
<label [attr.for]="id" class="horizontal control-label">
{{ schema.title }}
</label>
<div *ngIf="schema.type!='array'" class="checkbox">
<label class="horizontal control-label">
<input [formControl]="control"
[attr.name]="name"
[indeterminate]="control.value !== false && control.value !== true ? true :null"
type="checkbox"
[attr.disabled]="schema.readOnly">
<input *ngIf="schema.readOnly" [attr.name]="name" type="hidden" [formControl]="control"> {{schema.description}}
</label>
</div>
<ng-container *ngIf="schema.type==='array'">
<div *ngFor="let option of schema.items.oneOf" class="checkbox">
<label class="horizontal control-label">
<input [attr.name]="name"
value="{{option.enum[0]}}"
type="checkbox"
[attr.disabled]="schema.readOnly"
(change)="onCheck($event.target)"
[attr.checked]="checked[option.enum[0]] ? true : null">
{{option.description}}
</label>
</div>
</ng-container>
</div>
9 changes: 9 additions & 0 deletions ui/src/app/schema-form/widget/check/checkbox.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Component } from '@angular/core';

import { CheckboxWidget } from 'ngx-schema-form';

@Component({
selector: 'checkbox-component',
templateUrl: `./checkbox.component.html`
})
export class CustomCheckboxComponent extends CheckboxWidget { }

0 comments on commit f3b97a7

Please sign in to comment.