Created
November 7, 2016 10:10
-
-
Save ggkrustev/36990449075f95c42e189ba27c889390 to your computer and use it in GitHub Desktop.
angular-combobox-change-method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected change(candidate: any, isCustom: boolean = false): void { | |
const currentValue: any = Util.getter(this.value, this.valueField); | |
this.open = false; | |
if (isCustom) { | |
this.handleCustomValue(candidate, currentValue); | |
} else { | |
this.handleValue(candidate, currentValue); | |
} | |
this._previousValue = this.value; | |
this.onChangeCallback(this.value); | |
this.valueChange.emit(this.value); | |
} | |
protected handleCustomValue(candidate: any, currentValue: any): void { | |
this.dataItem = undefined; | |
if(!this.allowCustom) { | |
this.text = undefined; | |
this.value = undefined; | |
return; | |
} | |
const normalizedValue = this.normalizeValue(candidate); | |
if (Util.getter(normalizedValue, this.valueField) === currentValue) { | |
return; | |
} | |
this.value = normalizedValue; | |
} | |
protected handleValue(candidate: any, currentValue: any): void { | |
const newValue = Util.getter(candidate, this.valueField); | |
const newText = Util.getter(candidate, this.textField); | |
if (currentValue === newValue && this.text === newText) { | |
return; | |
} | |
this.dataItem = candidate; | |
this.value = this.valuePrimitive ? newValue : candidate; | |
this.text = newText; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment