Here is my angular reactive form setup:
zoneEntryForm = new FormGroup({
code: new FormControl(''),
zonename: new FormControl(''),
});
The output I'm getting from this code is:
onSubmit() {
// TODO: Use EventEmitter with form value
console.warn(this.zoneEntryForm.value);
}
output
https://i.sstatic.net/AxHc8.png
[Note: code is a number, zone is a string]
Now, I need to read the value from both the code and zone, but I want the code field to be disabled. The code is retrieved from the database and the user won't input it. Later, I need to send this code and zone name somewhere else.
Both fields should be blank by default.
Here are my attempts:
Attempt 1:
zoneEntryForm = new FormGroup({
code: new FormControl({value: '', disabled: true}),
zonename: new FormControl(''),
});
output: https://i.sstatic.net/SJ2eT.png
As you can see, the code field is no longer being read by onSubmit
Attempt 2:
zoneEntryForm = new FormGroup({
code: new FormControl({disabled: true}),
zonename: new FormControl(''),
});
output :
https://i.sstatic.net/A1ky2.png
Now, my default blank value is gone
So, how can I make the code field disabled and still be able to read from it properly at the same time?