Skip to content

Commit 4ebf6d1

Browse files
authored
Merge pull request #294 from IgniteUI/dkamburov/fix-291
Update the model on input event. Fix #291
2 parents 8fbf709 + 7883126 commit 4ebf6d1

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

src/igcombo/igcombo.component.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,29 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
4141
super.ngOnInit();
4242

4343
if (this._model) {
44+
if (this.options.allowCustomValue) {
45+
jQuery(this._el).on("input", function (evt) {
46+
that._model.viewToModelUpdate(evt.target.value);
47+
});
48+
49+
jQuery(this._el).closest(".ui-igcombo-wrapper").find(".ui-igcombo-clear").on("click", function() {
50+
if (that.options.multiSelection && that.options.multiSelection.enabled) {
51+
that._model.viewToModelUpdate([]);
52+
} else {
53+
that._model.viewToModelUpdate(null);
54+
}
55+
});
56+
}
57+
4458
// D.P. #244 only attach selectionchanged handler if there's a model to update
4559
jQuery(this._el).on(this._widgetName.toLowerCase() + "selectionchanged", function (evt, ui) {
4660
var items = ui.items;
4761
const valueKey = ui.owner.options.valueKey;
4862

4963
if (items.length <= 0 && !ui.owner.options.multiSelection.enabled) {
50-
that._model.viewToModelUpdate(null);
64+
if (!ui.owner.options.allowCustomValue) {
65+
that._model.viewToModelUpdate(null);
66+
}
5167
return;
5268
}
5369

tests/unit/igcombo/combo.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,35 @@ export function main() {
179179
});
180180
});
181181

182+
it('the ngModel should be updated correctly if the combo is allowing custom values', (done) => {
183+
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [(ngModel)]="combo.value1" [dataSource]="northwind" [allowCustomValue]="true"></ig-combo></div>';
184+
TestBed.overrideComponent(TestComponent, {
185+
set: {
186+
template: template
187+
}
188+
});
189+
TestBed.compileComponents().then(() => {
190+
let fixture = TestBed.createComponent(TestComponent);
191+
fixture.detectChanges();
192+
setTimeout(function () {
193+
//var elem = $("#combo1").igCombo("itemsFromIndex", 0)["element"];
194+
//$("#combo1").igCombo("select", elem, {}, true);
195+
$(fixture.debugElement.nativeElement).find("#combo1").val("foo").trigger("input");
196+
fixture.detectChanges();
197+
setTimeout(function () {
198+
expect(fixture.componentInstance.combo.value1).toEqual("foo");
199+
//clear
200+
$("#combo1").parents("ig-combo").find(".ui-igcombo-clearicon").click();
201+
fixture.detectChanges();
202+
setTimeout(function () {
203+
expect(fixture.componentInstance.combo.value1).toBeNull();
204+
done();
205+
}, 10);
206+
}, 10);
207+
}, 100);
208+
});
209+
});
210+
182211
it('the ngModel should be updated correctly if the combo selection is updated and multiple items are selected', (done) => {
183212
var template = '<div><ig-combo [(widgetId)]="comboID" [dataSource]="northwind" [(options)]="optionsMultipleSelection" [(ngModel)]="combo.value1"></ig-combo></div>';
184213
TestBed.overrideComponent(TestComponent, {

tests/unit/igeditors/editors.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ export function main() {
550550
fixture.detectChanges();
551551
setTimeout(() => {
552552
expect($(fixture.debugElement.nativeElement).find("#editor1").igTimePicker("displayValue")).toBe("5:50 AM");
553-
$(fixture.debugElement.nativeElement).find("#editor1").focus().trigger("focus").val("06:00 PM").blur().trigger("blur");
553+
$(fixture.debugElement.nativeElement).find("#editor1").focus().trigger("focus").val("06:00 AM").blur().trigger("blur");
554554
setTimeout(() => {
555555
expect(fixture.debugElement.componentInstance.val.getHours()).toBe(6);
556556
expect(fixture.debugElement.componentInstance.val.getMinutes()).toBe(0);

0 commit comments

Comments
 (0)