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

Commit

Permalink
fix: fixed checkbox input control
Browse files Browse the repository at this point in the history
  • Loading branch information
artemnih committed Dec 10, 2018
1 parent 000b0e9 commit 15696dc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dist/ngx-forms.js

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions src/app/components/form-checkbox/form-checkbox.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<div class="row" [formGroup]="group">
<label class="col-md-2 font-weight-bold col-form-label">{{ field.label }}
<label class="col-md-2 font-weight-bold col-form-label">{{field.label}}
<span class="required-icon" [hidden]="!field.required">*</span>
</label>
<div class="col-md-10">
<div class="row" *ngFor="let item of field.options">
<label class="col-md-6"><input type="checkbox" [formControlName]="field.name">{{ item }}</label>
</div>
<input type="text" class="form-control" [attr.placeholder]="field.placeholder" [formControlName]="field.name">
</div>
</div>
</div>
11 changes: 5 additions & 6 deletions src/app/components/form-checkbox/form-checkbox.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormCheckboxComponent as Type } from './form-checkbox.component';
import { FormCheckboxComponent as Type} from './form-checkbox.component';
import { ReactiveFormsModule, FormsModule, FormGroup, FormControl } from '@angular/forms';
import { APP_BASE_HREF } from '@angular/common';
import { By } from '@angular/platform-browser';
Expand All @@ -8,7 +8,7 @@ describe('FormCheckboxComponent', () => {
let component: Type;
let fixture: ComponentFixture<Type>;
let directiveEl;
let value = "bbb";
let value = true;

beforeEach(async(() => {
TestBed.configureTestingModule({
Expand All @@ -25,15 +25,14 @@ describe('FormCheckboxComponent', () => {
fixture = TestBed.createComponent(Type);
component = fixture.componentInstance;

component.field = { type: "checkbox", name: "test", required: true, options: ['aaa', 'bbb', 'ccc'] };
component.field = { type: "text", name: "test", required: true };
component.group = new FormGroup({
test: new FormControl('')
});
component.group.patchValue({
test: value
});


fixture.detectChanges();
});
}));
Expand All @@ -43,8 +42,8 @@ describe('FormCheckboxComponent', () => {
});

it('ensures component is rendered', () => {
directiveEl = fixture.debugElement.queryAll(By.css('input'));
expect(directiveEl.length).toEqual(component.field.options.length);
directiveEl = fixture.debugElement.query(By.css('input'));
expect(directiveEl.nativeElement.value.toString()).toEqual(value.toString());
});

it('ensures required asterix appears', () => {
Expand Down
5 changes: 2 additions & 3 deletions src/app/components/form-checkbox/form-checkbox.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Component } from '@angular/core';
import { Field } from '../../models/field.interface';
import { FormGroup } from '@angular/forms';
import { Field } from '../../models/field.interface';
import { IFieldConfig } from '../../models/field-config.interface';

@Component({
selector: 'form-checkbox',
template: require('./form-checkbox.component.html')
})

export class FormCheckboxComponent implements Field {
export class FormCheckboxComponent implements Field {
field: IFieldConfig;
group: FormGroup;
model: object;
Expand Down
4 changes: 1 addition & 3 deletions src/app/components/form-input/form-input.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormInputComponent as Type} from './form-input.component';
import { ReactiveFormsModule, FormsModule, FormBuilder, FormGroup, FormControl } from '@angular/forms';
import { ReactiveFormsModule, FormsModule, FormGroup, FormControl } from '@angular/forms';
import { APP_BASE_HREF } from '@angular/common';
import { By } from '@angular/platform-browser';

describe('FormInputComponent', () => {
let component: Type;
let fixture: ComponentFixture<Type>;
const formBuilder: FormBuilder = new FormBuilder();
let directiveEl;
let value = "Some Test Value";

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


fixture.detectChanges();
});
}));
Expand Down

0 comments on commit 15696dc

Please sign in to comment.