I'm trying to send an array stringified from a hidden input created in js, but the value never goes to the formBuilder.
The code that creates the hidden input from a different js file is:
$(form).append(
$('<input>')
.attr('type', 'hidden')
.attr('formControlName', 'selectedMessages')
.attr('ng-reflect-name', 'selectedMessages')
.val(JSON.stringify(selectedMessages))
);
It creates perfectly the hidden input and the value too, but never sends the info, what can i do to solve this?
this is my component.ts:
import { Component, OnInit } from '@angular/core';
import { searchClient } from '../inicio/inicio.component';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { FirestoreService } from '../../services/firestore/firestore.service'
import "../../js/TableJS.js";
const index = searchClient.initIndex('messages');
@Component({
selector: 'app-inbox',
templateUrl: './inbox.component.html',
styleUrls: ['./inbox.component.css']
})
export class InboxComponent implements OnInit {
messagesForm: FormGroup;
errorMessage: string = '';
successMessage: string = '';
constructor(
private fb: FormBuilder,
private fireservice: FirestoreService) {
}
ngOnInit() {
this.createForm();
}
createForm() {
this.messagesForm = this.fb.group({
selectedMessages: ['']
});
}
getUserByID(userId: string){
this.fireservice.getUserByID(userId);
}
console(value){
console.log(value);
}
getArchivedMessages(){
}
getInMessages(){
}
getOutMessages(){
}
deleteMessage(){
}
archiveMessage(){
}
checkForFullMsgDelete(){
}
}
the input that creates when i click the button that calls the (form).append is:
input type="hidden" formcontrolname="selectedMessages" ng-reflect-name="selectedMessages" value="["selectedmessages values"]";
on submit i call console(messagesForm.value), and its always empty, not totally because it sends the empty variable "selectedMessages" from the formBuilder, but you know what i mean.
What I have tried:
I've tried FromArray, doing the submit after the input is created.. and more things i don't remember right now