Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
125
Issue with Change Event on igxInput
posted

I am trying to build a custom component which uses igxInput and an IgsDropdown component in Angular. The user types a User name and we fire of a query to narrow down the list of names we display for the user to select. Al good so far. Once the user selects a name from the list we show another dropdown box which shows the relationship type of the Person.

<form novalidate [formGroup]="form">

    <div class="inputs">
        <igx-input-group #inputGroup
                         [class.igx-input-group--required]="isRequired"
                         [class.igx-input-group--invalid]="!selected.valid">
            <input igxInput #inputForm (keyup.enter)="null"
                   class="search-input"
                   (keydown)="toggleDropDown($event)"
                   (input)="onSearch($event.target.value)"
                   (change)="clearSelected($event)"
                   (focusout)="clickedOutside($event)"
                   (keydown.ArrowDown)="openDropDown()"
                   type="text" [igxDropDownItemNavigation]="dropdown" />
            <label igxLabel>{{label}} <span *ngIf="isRequired">&nbsp;*</span></label>
        </igx-input-group>

        <igx-drop-down #dropdown (onSelection)="itemSelection($event)"
                       (onOpened)="onDropDownOpen()"
                       (onClosed)="onDropDownClose()">
            <igx-drop-down-item *ngFor="let item of selectOptions"
                                [value]="item.value">
                <div class="igx-drop-down__item-template">
                    <span>{{item.name}}</span>
                </div>
            </igx-drop-down-item>
        </igx-drop-down>
    </div>

</form>

i register a change hook on the Input (change)="clearSelected($event)" so if the user changes the value we will remove the selected value which in turn invalidates the control and prevents user from submitting. So far all works except every time i click on the dropdown of the dropdown box it for some reason it calls the change event on first one. Then the second time it no longer does that. So how can i make sure the change event is only called when the input value actually changes ?