0

I have a checkbox based on selecting the checkbox, the values must be shown in the dropdown. But here, when i "unselect" both the checkboxes and again select both and "unselect" one, then the dropdown values remains same, it doesn't reset. Can anyone help me to sort out this?

DEMO

Ts:

 setFaxId(index: number, faxQue: any) {
        faxQue.isChecked = (faxQue.isChecked) ? false : true;
        let filteredArr = this.faxqueuelists.filter(x=>x.faxQueueID == faxQue.faxQueueID);
        if (faxQue.isChecked) {
            this._selectedFaxQueList.push(faxQue.faxQueueID);
            this.dropDownFaxQueueList.push(filteredArr[0]);
            if(this.dropDownFaxQueueList.length == 1){
                this.userGroup.get("DefaultFaxQueue").patchValue(faxQue.faxQueueID);
            }

        } else {
            this._selectedFaxQueList.splice(this._selectedFaxQueList.indexOf(faxQue.faxQueueID), 1);
            this.dropDownFaxQueueList.splice(this._selectedFaxQueList.indexOf(faxQue.faxQueueID),1);
            this.userGroup.get("DefaultFaxQueue").patchValue("");
        }
    }
0

1 Answer 1

1

Replace the else part by this:

let index = this._selectedFaxQueList.indexOf(faxQue.faxQueueID);
this._selectedFaxQueList.splice(index, 1);
this.dropDownFaxQueueList.splice(index,1);

The selected element is already deleted from _selectedFaxQueList, when doing the indexOf() second time (in your code), it won't give a proper result.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, thanks for your response, this is working for me, but here, the selected value is not setting as default on the dropdown input
i have 2 dropdowns, in that i had selected only one, after refresh, the input field is empty, it gives only the dropdown
It seems to be working fine for me. See the console, there is an error for the form. You may want to fix that before trying anything else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.