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