Skip to content
This repository was archived by the owner on Aug 25, 2020. It is now read-only.

Commit 15696dc

Browse files
committed
fix: fixed checkbox input control
1 parent 000b0e9 commit 15696dc

File tree

5 files changed

+12
-18
lines changed

5 files changed

+12
-18
lines changed

dist/ngx-forms.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<div class="row" [formGroup]="group">
2-
<label class="col-md-2 font-weight-bold col-form-label">{{ field.label }}
2+
<label class="col-md-2 font-weight-bold col-form-label">{{field.label}}
33
<span class="required-icon" [hidden]="!field.required">*</span>
44
</label>
55
<div class="col-md-10">
6-
<div class="row" *ngFor="let item of field.options">
7-
<label class="col-md-6"><input type="checkbox" [formControlName]="field.name">{{ item }}</label>
8-
</div>
6+
<input type="text" class="form-control" [attr.placeholder]="field.placeholder" [formControlName]="field.name">
97
</div>
10-
</div>
8+
</div>

src/app/components/form-checkbox/form-checkbox.component.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2-
import { FormCheckboxComponent as Type } from './form-checkbox.component';
2+
import { FormCheckboxComponent as Type} from './form-checkbox.component';
33
import { ReactiveFormsModule, FormsModule, FormGroup, FormControl } from '@angular/forms';
44
import { APP_BASE_HREF } from '@angular/common';
55
import { By } from '@angular/platform-browser';
@@ -8,7 +8,7 @@ describe('FormCheckboxComponent', () => {
88
let component: Type;
99
let fixture: ComponentFixture<Type>;
1010
let directiveEl;
11-
let value = "bbb";
11+
let value = true;
1212

1313
beforeEach(async(() => {
1414
TestBed.configureTestingModule({
@@ -25,15 +25,14 @@ describe('FormCheckboxComponent', () => {
2525
fixture = TestBed.createComponent(Type);
2626
component = fixture.componentInstance;
2727

28-
component.field = { type: "checkbox", name: "test", required: true, options: ['aaa', 'bbb', 'ccc'] };
28+
component.field = { type: "text", name: "test", required: true };
2929
component.group = new FormGroup({
3030
test: new FormControl('')
3131
});
3232
component.group.patchValue({
3333
test: value
3434
});
3535

36-
3736
fixture.detectChanges();
3837
});
3938
}));
@@ -43,8 +42,8 @@ describe('FormCheckboxComponent', () => {
4342
});
4443

4544
it('ensures component is rendered', () => {
46-
directiveEl = fixture.debugElement.queryAll(By.css('input'));
47-
expect(directiveEl.length).toEqual(component.field.options.length);
45+
directiveEl = fixture.debugElement.query(By.css('input'));
46+
expect(directiveEl.nativeElement.value.toString()).toEqual(value.toString());
4847
});
4948

5049
it('ensures required asterix appears', () => {

src/app/components/form-checkbox/form-checkbox.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { Component } from '@angular/core';
2-
import { Field } from '../../models/field.interface';
32
import { FormGroup } from '@angular/forms';
3+
import { Field } from '../../models/field.interface';
44
import { IFieldConfig } from '../../models/field-config.interface';
55

66
@Component({
77
selector: 'form-checkbox',
88
template: require('./form-checkbox.component.html')
99
})
10-
11-
export class FormCheckboxComponent implements Field {
10+
export class FormCheckboxComponent implements Field {
1211
field: IFieldConfig;
1312
group: FormGroup;
1413
model: object;

src/app/components/form-input/form-input.component.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22
import { FormInputComponent as Type} from './form-input.component';
3-
import { ReactiveFormsModule, FormsModule, FormBuilder, FormGroup, FormControl } from '@angular/forms';
3+
import { ReactiveFormsModule, FormsModule, FormGroup, FormControl } from '@angular/forms';
44
import { APP_BASE_HREF } from '@angular/common';
55
import { By } from '@angular/platform-browser';
66

77
describe('FormInputComponent', () => {
88
let component: Type;
99
let fixture: ComponentFixture<Type>;
10-
const formBuilder: FormBuilder = new FormBuilder();
1110
let directiveEl;
1211
let value = "Some Test Value";
1312

@@ -34,7 +33,6 @@ describe('FormInputComponent', () => {
3433
test: value
3534
});
3635

37-
3836
fixture.detectChanges();
3937
});
4038
}));

0 commit comments

Comments
 (0)