separate choice from form
This commit is contained in:
parent
186e5e36da
commit
f6ce22480c
|
@ -9,6 +9,7 @@ import { Router } from '@angular/router';
|
||||||
import { environment } from '../../../../environments/environment';
|
import { environment } from '../../../../environments/environment';
|
||||||
import { PollUtilitiesService } from '../../../core/services/poll.utilities.service';
|
import { PollUtilitiesService } from '../../../core/services/poll.utilities.service';
|
||||||
import { StorageService } from '../../../core/services/storage.service';
|
import { StorageService } from '../../../core/services/storage.service';
|
||||||
|
import { defaultDates, defaultTimeOfDay } from '../../../../../mocks/old-stuff/config/defaultConfigs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-admin-form',
|
selector: 'app-admin-form',
|
||||||
|
@ -53,29 +54,29 @@ export class FormComponent implements OnInit {
|
||||||
creatorEmail: ['', [Validators.required]],
|
creatorEmail: ['', [Validators.required]],
|
||||||
custom_url: [this.pollUtilitiesService.makeUuid(), [Validators.required]],
|
custom_url: [this.pollUtilitiesService.makeUuid(), [Validators.required]],
|
||||||
description: ['', [Validators.required]],
|
description: ['', [Validators.required]],
|
||||||
choices: this.fb.array([
|
// choices: this.fb.array([
|
||||||
this.fb.group({
|
// this.fb.group({
|
||||||
label: ['', [Validators.required]],
|
// label: ['', [Validators.required]],
|
||||||
imageUrl: ['', [Validators.required]],
|
// imageUrl: ['', [Validators.required]],
|
||||||
}),
|
// }),
|
||||||
]),
|
// ]),
|
||||||
dateChoices: this.fb.array([
|
// dateChoices: this.fb.array([
|
||||||
this.fb.group({
|
// this.fb.group({
|
||||||
label: ['', [Validators.required]],
|
// label: ['', [Validators.required]],
|
||||||
// if we have enabled detailed time choices per date choice, we have to make a time property for each date choice
|
// // if we have enabled detailed time choices per date choice, we have to make a time property for each date choice
|
||||||
timeChoices: this.fb.array([
|
// timeChoices: this.fb.array([
|
||||||
this.fb.group({
|
// this.fb.group({
|
||||||
label: ['', [Validators.required]],
|
// label: ['', [Validators.required]],
|
||||||
}),
|
// }),
|
||||||
]),
|
// ]),
|
||||||
}),
|
// }),
|
||||||
]),
|
// ]),
|
||||||
// these time choice are meant to be the same for each day
|
// // these time choice are meant to be the same for each day
|
||||||
timeChoices: this.fb.array([
|
// timeChoices: this.fb.array([
|
||||||
this.fb.group({
|
// this.fb.group({
|
||||||
label: ['', [Validators.required]],
|
// label: ['', [Validators.required]],
|
||||||
}),
|
// }),
|
||||||
]),
|
// ]),
|
||||||
kind: ['', [Validators.required]],
|
kind: ['', [Validators.required]],
|
||||||
areResultsPublic: [true, [Validators.required]],
|
areResultsPublic: [true, [Validators.required]],
|
||||||
whoCanChangeAnswers: ['everybody', [Validators.required]],
|
whoCanChangeAnswers: ['everybody', [Validators.required]],
|
||||||
|
@ -141,18 +142,14 @@ export class FormComponent implements OnInit {
|
||||||
startDateInterval: new Date(),
|
startDateInterval: new Date(),
|
||||||
endDateInterval: new Date(),
|
endDateInterval: new Date(),
|
||||||
comments: [],
|
comments: [],
|
||||||
choices: [
|
// choices: [
|
||||||
{
|
// {
|
||||||
name: 'un choix',
|
// name: 'un choix',
|
||||||
url: 'https://placekitten.com/120/150',
|
// url: 'https://placekitten.com/120/150',
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
dateChoices: [
|
// dateChoices: defaultDates,
|
||||||
{
|
// timeChoices: defaultTimeOfDay,
|
||||||
name: new Date(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
timeChoices: [],
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
<div class="validation-error-list" [ngClass]="{ 'has-background-warning': totalErrors > 0 }">
|
<div
|
||||||
|
class="validation-error-list padded"
|
||||||
|
[ngClass]="{ 'has-background-warning': totalErrors > 0, 'has-background-success': totalErrors === 0 }"
|
||||||
|
>
|
||||||
<h1 class="title is-1">
|
<h1 class="title is-1">
|
||||||
Validation
|
Validation
|
||||||
</h1>
|
</h1>
|
||||||
<span class="status"> statut: {{ form.status }} </span>
|
<span class="status marged"> statut: {{ form.status }} </span>
|
||||||
<span class="has-background-warning total-errors" *ngIf="form && getFormValidationErrors()">
|
<strong class="marged has-background-warning total-errors" *ngIf="form && totalErrors">
|
||||||
{{ totalErrors }} erreurs de validation
|
{{ totalErrors }} erreurs de validation
|
||||||
</span>
|
</strong>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li *ngFor="let m of messages">
|
<li *ngFor="let m of messages">
|
||||||
|
|
|
@ -24,7 +24,14 @@ export class ErrorsListComponent implements OnInit {
|
||||||
this.messages = [];
|
this.messages = [];
|
||||||
|
|
||||||
Object.keys(this.form.controls).forEach((key) => {
|
Object.keys(this.form.controls).forEach((key) => {
|
||||||
const controlErrors: ValidationErrors = this.form.get(key).errors;
|
const theKey = this.form.get(key);
|
||||||
|
const invalidData = theKey.invalid;
|
||||||
|
if (invalidData) {
|
||||||
|
totalErrors++;
|
||||||
|
console.log('key', key, invalidData);
|
||||||
|
this.messages.push('' + key + ' est invalide');
|
||||||
|
}
|
||||||
|
const controlErrors: ValidationErrors = theKey.errors;
|
||||||
if (controlErrors != null) {
|
if (controlErrors != null) {
|
||||||
console.log('controlErrors', controlErrors);
|
console.log('controlErrors', controlErrors);
|
||||||
totalErrors++;
|
totalErrors++;
|
||||||
|
|
Loading…
Reference in New Issue