Commit b3eaa941 by Riina Antikainen

New event buttons works

1 parent d3586d07
...@@ -16,7 +16,7 @@ export class EventListComponent implements OnInit, OnChanges { ...@@ -16,7 +16,7 @@ export class EventListComponent implements OnInit, OnChanges {
} }
onClick() { onClick() {
console.log('Nappitoimii'); console.log('Button works');
} }
ngOnInit() { ngOnInit() {
...@@ -26,7 +26,8 @@ export class EventListComponent implements OnInit, OnChanges { ...@@ -26,7 +26,8 @@ export class EventListComponent implements OnInit, OnChanges {
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
console.log('toimii', changes, this.organization.name); console.log('toimii', changes, this.organization.name);
this.events = this.appService.get(changes.organization.currentValue); this.events = this.appService.get(this.organization.name);
// this.events = this.appService.get(changes.organization.currentValue);
console.log('ei toi'); console.log('ei toi');
} }
} }
...@@ -5,7 +5,7 @@ export class EventsService { ...@@ -5,7 +5,7 @@ export class EventsService {
get(org: String) { get(org: String) {
console.log(org); console.log(org);
if (org === 'Assemly') { if (org === 'Assembly') {
return [ return [
{title: 'Assembly Winter 18', date: '1.2.2018 - 3.2.2018'}, {title: 'Assembly Winter 18', date: '1.2.2018 - 3.2.2018'},
{title: 'Assembly Summer 18', date: '1.2.2018 - 3.2.2018'}, {title: 'Assembly Summer 18', date: '1.2.2018 - 3.2.2018'},
......
<form [formGroup]="eventForm" (ngSubmit)="onSubmit()"> <form [formGroup]="form" (ngSubmit)="onSubmit()">
<mat-form-field> <mat-form-field>
<input matInput required placeholder="Event name" formControlName="name"> <input matInput required placeholder="Event name" formControlName="name">
</mat-form-field> </mat-form-field>
...@@ -9,5 +9,6 @@ ...@@ -9,5 +9,6 @@
<input matInput required placeholder="Url" formControlName="url"> <input matInput required placeholder="Url" formControlName="url">
</mat-form-field> </mat-form-field>
<button mat-button (click)='onSubmit()'>Submit</button> <button mat-button type="submit" [disabled]="!form.valid">Submit</button>
<button mat-button (ngClick)="goBack()">Back</button>
</form> </form>
\ No newline at end of file
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms'; import { FormControl, FormGroup, FormBuilder, Validators} from '@angular/forms';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
@Component({ @Component({
...@@ -9,22 +9,27 @@ import { Router } from '@angular/router'; ...@@ -9,22 +9,27 @@ import { Router } from '@angular/router';
}) })
export class NewEventComponent implements OnInit { export class NewEventComponent implements OnInit {
public eventForm = new FormGroup({ form: FormGroup;
name: new FormControl(),
url: new FormControl()
});
constructor(private _router: Router) { } constructor(private formBuilder: FormBuilder, private _router: Router) { }
ngOnInit() { ngOnInit() {
this.form = this.formBuilder.group({
name: [null, Validators.required],
url: [null, Validators.required]
});
} }
onSubmit() { onSubmit() {
const values = { const values = {
'name': this.eventForm.get('name').value, 'name': this.form.get('name').value,
'url': this.eventForm.get('url').value, 'url': this.form.get('url').value
}; };
this._router.navigate(['/organization']); this._router.navigate(['/organization']);
} }
goBack() {
this._router.navigate(['/organization']);
}
} }
...@@ -18,7 +18,7 @@ export class OrganizationListComponent implements OnInit { ...@@ -18,7 +18,7 @@ export class OrganizationListComponent implements OnInit {
public organizations: Organization[] = [ public organizations: Organization[] = [
{id: 1, name: 'Assembly Organization'}, {id: 1, name: 'Assembly Organization'},
{id: 3, name: 'Assemly'}, {id: 3, name: 'Assembly'},
{id: 30, name: 'Organization'} {id: 30, name: 'Organization'}
]; ];
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!