-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from riot-appstore/pr/reactive_forms
Add Reactive Forms support
- Loading branch information
Showing
12 changed files
with
208 additions
and
97 deletions.
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
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,15 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
|
||
import { DynFormService } from './dyn-form.service'; | ||
|
||
describe('DynFormService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [DynFormService] | ||
}); | ||
}); | ||
|
||
it('should be created', inject([DynFormService], (service: DynFormService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
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,19 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { FormElementBase } from './models'; | ||
import { FormControl, FormGroup, Validators } from '@angular/forms'; | ||
|
||
@Injectable() | ||
export class DynFormService { | ||
|
||
constructor() { } | ||
|
||
toFormGroup(elements: FormElementBase<any>[] ) { | ||
let group: any = {}; | ||
|
||
elements.forEach(el => { | ||
group[el.key] = el.required ? new FormControl(el.value || '', Validators.required) | ||
: new FormControl(el.value || ''); | ||
}); | ||
return new FormGroup(group); | ||
} | ||
} |
Empty file.
11 changes: 11 additions & 0 deletions
11
rapstore-frontend/src/app/form-element/form-element.component.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,11 @@ | ||
<div [formGroup]="form" class="form-group"> | ||
<label class="center-block">{{element.label}}</label> | ||
|
||
<div [ngSwitch]="element.controlType"> | ||
<input *ngSwitchCase="'textbox'" [formControlName]="element.key" | ||
[id]="element.key" [type]="element.type" class="form-control"> | ||
<textarea *ngSwitchCase="'textarea'" ref-textarea [formControlName]="element.key" class="form-control" rows=12></textarea> | ||
<input *ngSwitchCase="'file'" type="file" accept=".tar.gz" [formControlName]="element.key" (change)="onChange($event)"> | ||
</div> | ||
<!--<div class="errorMessage" *ngIf="!isValid">{{question.label}} is required</div>--> | ||
</div> |
25 changes: 25 additions & 0 deletions
25
rapstore-frontend/src/app/form-element/form-element.component.spec.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,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { FormElementComponent } from './form-element.component'; | ||
|
||
describe('FormElementComponent', () => { | ||
let component: FormElementComponent; | ||
let fixture: ComponentFixture<FormElementComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ FormElementComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(FormElementComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
rapstore-frontend/src/app/form-element/form-element.component.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,21 @@ | ||
import { Component, Input, Output, EventEmitter } from '@angular/core'; | ||
import { FormElementBase } from '../models'; | ||
import { FormGroup} from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'app-form-element', | ||
templateUrl: './form-element.component.html', | ||
styleUrls: ['./form-element.component.css'] | ||
}) | ||
|
||
export class FormElementComponent { | ||
@Input() element: FormElementBase<any>; | ||
@Input() form: FormGroup; | ||
@Output() notify_file: EventEmitter<File> = new EventEmitter<File>(); | ||
// get isValid() { return this.form.controls[this.element.key].valid; } | ||
onChange(event) { | ||
let file: File = event.target.files.length > 0 && event.target.files[0]; | ||
this.notify_file.emit(file); | ||
} | ||
|
||
} |
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
Oops, something went wrong.