0
I have a code where the person must select a modality of the academy, for example, the martial arts plan, the person must select which fight she wants. So I made the following code:
<div class="btn-group-vertical btn-group-toggle col-4"
data-toggle="buttons"
id="modalidade"
>
<div *ngFor="let modalidades of planoDados?.PlanoModalidades">
<label class="btn btn-outline-success col teste">
<input
#checkbox
type="checkbox"
name="modalidades"
(click)="addCheckbox(checkbox.value)"
[value]="modalidades.PlanoModalidadeID"
[checked]="modalidades.PlanoModalidadeObrigatoria === '1'"
[disabled]="modalidades.PlanoModalidadeObrigatoria === '1'"
/>
<span class="lead">
{{ modalidades?.PlanoModalidadeDescricao }}
</span>
</label>
</div>
</div>
The logic is, display a checkbox for each existing mode, the value will be the ID of the mode, but if one of the modality is mandatory, it is already checked and disabled, I created an array that will receive exactly the values of each checkbox.
I made that TS code:
private myCheckBox: any[] = [];
addCheckbox(i) {
let index = this.checkBox.indexOf(i)
if (index === -1) {
this.checkBox.push(i)
} else {
this.checkBox.splice(index, 1)
}
}
But I don’t get the checkbox value that’s checked and disabled, any way to fix it? Or even a better way to pick up checkboxes marked than their value. How to get the "checked" property from a checkbox?
Just take the modalities that are already mandatory in planoDados.Planomodalities[] and join with those being marked in Html.
– LeAndrade
It is worth creating an array for all marked modalities and for the mandatory, put it in the array in ngOnInit?
– Ban
Dude I would do that, pick the obligatory ones would put in an array along with the ones being marked.
– LeAndrade
The problem is this, how do I take the value of what is already marked by being mandatory?
– Ban