lundi 25 décembre 2017

ngModel checks my checkboxes?

I'm using a form with hundreds of checkboxes for my shop search engine. Everything works smoothly, except that ngModel seems that checks all of my checkboxes. Why is that? I don't see checked anywhere in the Elements tab in my browser...

HTML:

<form #filterForm="ngForm" *ngIf="properties">
    <fieldset ngModelGroup="inputs" #inputs="ngModelGroup">
        <button type="button" class="btn btn-primary" style="width: 100%;" (click)="toggleTab('filters')">Филтриране на резултатите</button>
        <div id="filters" style="display: none;">
            <hr />
            <div class="row">
                <div class="col-sm-6" *ngFor="let property of properties.SearchPropertyInfoList.Content.Item">
                    <h5></h5>
                    <div class="filter">
                        <label class="custom-control custom-checkbox" *ngFor="let value of property.Values.PropertyValue">
                        <input type="checkbox" name="" 
                                [ngModel]="property.Id + '-' + value.Id" class="custom-control-input" />
                        <span class="custom-control-indicator"></span>
                        <span class="custom-control-description"></span></label>
                    </div>
                </div>
            </div>
            <hr />
            <button type="button" class="btn btn-primary" style="width: 100%;" (click)="searchBy(filterForm)">Запази филтрите</button>
        </div>
    </fieldset>
</form>

JS:

searchBy(filterForm) {
    console.log(filterForm.form.value.inputs);
}


EDIT:

Also, how can I join the values of the inputs as a comma-separated string? They should become: 1627207-3232483,1627207-3232484.... I've tried with filterForm.form.value.inputs.join(), but it gives join is not a function error.

{"1627207-3232483":"1627207-3232483","1627207-3232484":"1627207-3232484","1627207-3232481":"1627207-3232481"}




Aucun commentaire:

Enregistrer un commentaire