mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
add form array for choices
This commit is contained in:
parent
8cac3d1862
commit
d9301559ef
@ -52,6 +52,12 @@
|
||||
>
|
||||
<i class="fa fa-close"></i>
|
||||
</button>
|
||||
<h2>Choix de réponses</h2>
|
||||
<pre class="debug padded warning">
|
||||
choicesFormArray :
|
||||
{{ choicesFormArray | json }}
|
||||
</pre
|
||||
>
|
||||
|
||||
<label for="slug"
|
||||
>Url pour les participants
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Poll } from '../../../core/models/poll.model';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { UuidService } from '../../../core/services/uuid.service';
|
||||
import { DateService } from '../../../core/services/date.service';
|
||||
import { ApiService } from '../../../core/services/api.service';
|
||||
import { Choice } from '../../../core/models/choice.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin-form',
|
||||
@ -15,6 +16,9 @@ export class FormComponent implements OnInit {
|
||||
public poll?: Poll;
|
||||
public pollFormGroup: FormGroup;
|
||||
public configurationFormGroup: FormGroup;
|
||||
|
||||
public choicesFormArray: FormArray; // possible choices to answer
|
||||
|
||||
public longFormVersionEnabled = true;
|
||||
|
||||
public urlPrefix: string = window.location.origin + '/participation/';
|
||||
@ -27,6 +31,17 @@ export class FormComponent implements OnInit {
|
||||
slug: [this.poll ? this.poll.slug : this.uuidService.getUUID(), [Validators.required]],
|
||||
description: [this.poll ? this.poll.description : ''],
|
||||
});
|
||||
// add dynamically elements to add choices
|
||||
this.choicesFormArray = this.fb.array([
|
||||
{
|
||||
choices: this.poll.choices.forEach((elem: Choice) => {
|
||||
return {
|
||||
label: [elem.label, [Validators.required]],
|
||||
imageUrl: [elem.imageUrl, null],
|
||||
};
|
||||
}),
|
||||
},
|
||||
]);
|
||||
|
||||
this.configurationFormGroup = this.fb.group({
|
||||
isAboutDate: [this.poll ? this.poll.configuration.isAboutDate : false, [Validators.required]],
|
||||
@ -63,7 +78,6 @@ export class FormComponent implements OnInit {
|
||||
}
|
||||
public updateSlug() {
|
||||
let newValueFormatted = 'TODO';
|
||||
this.pollFormGroup.patchValue({ slug: newValueFormatted });
|
||||
}
|
||||
// this.pollFormGroup.setValue({'slug' : newValueFormatted);
|
||||
// }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user