fix default values for creation validation

This commit is contained in:
Tykayn 2021-11-12 13:27:18 +01:00 committed by tykayn
parent d68ba7ac2a
commit 96ef61c541
2 changed files with 20 additions and 18 deletions

View File

@ -112,22 +112,23 @@ export class PollService implements Resolve<Poll> {
} }
public createFormGroup() { public createFormGroup() {
let minlengthValidation = environment.production ? 12 : 0;
let form = this.fb.group({ let form = this.fb.group({
title: ['', [Validators.required, Validators.minLength(12)]], title: ['', [Validators.required, Validators.minLength(minlengthValidation)]],
creatorPseudo: ['', [Validators.required]], creatorPseudo: ['', [Validators.required]],
created_at: [new Date(), [Validators.required]], created_at: [new Date(), [Validators.required]],
creatorEmail: ['', [Validators.required]], creatorEmail: ['', [Validators.required]],
custom_url: [this.uuidService.getUUID(), [Validators.required]], custom_url: [this.uuidService.getUUID(), [Validators.required]],
description: ['', [Validators.required]], description: ['', [Validators.required]],
password: ['', [Validators.required]], password: ['', []],
choices: new FormArray([]), choices: new FormArray([]),
whoModifiesAnswers: ['', [Validators.required]], whoModifiesAnswers: ['', [Validators.required]],
whoCanChangeAnswers: ['', [Validators.required]], whoCanChangeAnswers: ['', [Validators.required]],
isAboutDate: [true, [Validators.required]], isAboutDate: [true, [Validators.required]],
startDateInterval: ['', [Validators.required]], // startDateInterval: ['', [Validators.required]],
endDateInterval: ['', [Validators.required]], // endDateInterval: ['', [Validators.required]],
expiresDaysDelay: ['', [Validators.required]], expiresDaysDelay: [60, []],
maxCountOfAnswers: ['', [Validators.required]], maxCountOfAnswers: [300, []],
isZeroKnoledge: [false, [Validators.required]], isZeroKnoledge: [false, [Validators.required]],
isProtectedByPassword: [false, [Validators.required]], isProtectedByPassword: [false, [Validators.required]],
isOwnerNotifiedByEmailOnNewVote: [true, [Validators.required]], isOwnerNotifiedByEmailOnNewVote: [true, [Validators.required]],
@ -140,7 +141,7 @@ export class PollService implements Resolve<Poll> {
allowComments: [true, [Validators.required]], allowComments: [true, [Validators.required]],
hasMaxCountOfAnswers: [300, [Validators.required]], hasMaxCountOfAnswers: [300, [Validators.required]],
useVoterUniqueLink: [false, [Validators.required]], useVoterUniqueLink: [false, [Validators.required]],
voterEmailList: ['', [Validators.required]], voterEmailList: ['', []],
allowNewDateTime: [60, [Validators.required, Validators.min(0)]], allowNewDateTime: [60, [Validators.required, Validators.min(0)]],
}); });
this.form = form; this.form = form;
@ -160,11 +161,12 @@ export class PollService implements Resolve<Poll> {
isProtectedByPassword: false, isProtectedByPassword: false,
richTextMode: false, richTextMode: false,
areResultsPublic: true, areResultsPublic: true,
expiracyNumberOfDays: 60, expiresDayDelay: 60,
maxCountOfAnswers: 300, maxCountOfAnswers: 300,
voterEmailList: '', voterEmailList: '',
password: '', password: '',
}); });
this.setDefaultDatesForInterval();
} }
public updateSlug(): void { public updateSlug(): void {
@ -376,15 +378,19 @@ export class PollService implements Resolve<Poll> {
} }
} }
public createPoll(): void { public createPoll(): Promise<any> {
this.toastService.display('sending...'); this.toastService.display('sending...');
console.log('this.form', this.form); console.log('this.form', this.form);
const newpoll = this.newPollFromForm(); const newpoll = this.newPollFromForm();
this.apiService.createPoll(newpoll).then((resp) => { return this.apiService.createPoll(newpoll).then(
console.log('poll created resp', resp); (resp: any) => {
console.log('TODO fill admin_key'); console.log('poll created resp', resp);
// this.admin_key = resp.data.admin_key; console.log('TODO fill admin_key');
}); console.log('resp', resp);
this.admin_key = resp.data.poll.admin_key;
},
(error) => this.apiService.ousideHandleError(error)
);
} }
/** /**

View File

@ -54,10 +54,6 @@
</button> </button>
</div> </div>
<div class="column"> <div class="column">
<button class="btn is-primary" (click)="createPoll()">
<i class="fa fa-save"></i>
Enregistrer le sondage
</button>
<button class="btn is-primary" (click)="createPoll()" [disabled]="!pollService.form.valid"> <button class="btn is-primary" (click)="createPoll()" [disabled]="!pollService.form.valid">
<i class="fa fa-save"></i> <i class="fa fa-save"></i>
Enregistrer le sondage Enregistrer le sondage