Rohit Adhikari
Rohit Adhikari

Reputation: 95

How can i stop a dropdownlist from value change on selection in kendo/angular

I want the control of dropdown list value selection change. I want to stop the selected value change in the dropdownlist.

I have kendo dropdown list, on its triggering valueChange event.

<kendo-dropdownlist #dropdownlist required [data]="responseTypes" 
                                [defaultItem]="{responseTypeID: null, responseTypeName: 'Select Response Type'}"
                                [textField]="'responseTypeName'"
                                [valueField]="'responseTypeID'"
                                name="responseTypeId"
                                [(ngModel)]="selectedResponseType"
                                (valueChange)="responseTypeChange($event)"
                                #responseTypeIdVar="ngModel" class="form-control" style="width:180px;">

</kendo-dropdownlist>

Upvotes: 1

Views: 2734

Answers (2)

Here is one solution I got from Kendo Team using the ChangeDetectorRef. Called the detectChanges before reassigning this.value. The valueChange event is not preventable, you have to manually reset the value of the component as desired

Click here for the example

Upvotes: 1

Geggi632
Geggi632

Reputation: 564

It's not the best answer and I hope you will find a better one but it's working..

bindings:

<kendo-dropdownlist [value]="selectedVal"
  (valueChange)="valueChange($event)">

valueChange() code:

public valueChange(value: any): void {
    let valToShow = this.selectedVal;
    this.newVal = value;
    setTimeout(() => {
      this.selectedVal = "changeToSomethingOther";
    }, 1);
    setTimeout(() => {
      this.selectedVal = valToShow;
    }, 1);
    this.open('dialog');
    this.log('valueChange', value);
  }

What I'm doing is to change the binded value to something different and then back to the old value but you have to do it in setTimeOut to trigger the change detection.

Upvotes: 0

Related Questions