Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev valbano 897 #914

Merged
merged 4 commits into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label typeahead-widget"
[class.is-dirty]="value"
[class.typeahead-widget__invalid]="!field.isValid">
[class.typeahead-widget__invalid]="!field.isValid" id="typehead-div">
<input class="mdl-textfield__input"
type="text"
[attr.id]="field.id"
[(ngModel)]="value"
(ngModelChange)="checkVisibility(field)"
(keyup)="onKeyUp($event)"
(blur)="onBlur()"
[disabled]="field.readOnly">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe('TypeaheadWidget', () => {
it('should get filtered options', () => {
let options: FormFieldOption[] = [
{ id: '1', name: 'Item one' },
{ id: '2', name: 'Item two'}
{ id: '2', name: 'Item two' }
];
widget.field.options = options;
widget.value = 'tw';
Expand Down Expand Up @@ -275,8 +275,8 @@ describe('TypeaheadWidget', () => {

it('should reset fields when flushing missing option value', () => {
widget.field.options = [
{id: '1', name: 'Item one'},
{id: '2', name: 'Item two'}
{ id: '1', name: 'Item one' },
{ id: '2', name: 'Item two' }
];
widget.value = 'Missing item';
widget.flushValue();
Expand All @@ -287,8 +287,8 @@ describe('TypeaheadWidget', () => {

it('should reset fields when flushing incorrect value', () => {
widget.field.options = [
{id: '1', name: 'Item one'},
{id: '2', name: 'Item two'}
{ id: '1', name: 'Item one' },
{ id: '2', name: 'Item two' }
];
widget.field.value = 'Item two';
widget.value = 'Item two!';
Expand All @@ -308,4 +308,33 @@ describe('TypeaheadWidget', () => {
expect(widget.field.value).toBeNull();
});

it('should emit field change event on item click', () => {
let event = jasmine.createSpyObj('event', ['preventDefault']);
let fakeField = new FormFieldModel(new FormModel(), {id: 'fakeField', value: 'fakeValue'});
widget.field = fakeField;
let item = {id: 'fake-id-opt', name: 'fake-name-opt'};
widget.onItemClick(item, event);

widget.fieldChanged.subscribe((field) => {
expect(field).toBeDefined();
expect(field.id).toEqual('fakeField');
expect(field.value).toEqual('fake-id-opt');
});
});

it('should emit field change event on blur', (done) => {
spyOn(widget, 'flushValue').and.stub();
let fakeField = new FormFieldModel(new FormModel(), {id: 'fakeField', value: 'fakeValue'});
widget.field = fakeField;
widget.onBlur();

setTimeout(() => {
widget.fieldChanged.subscribe((field) => {
expect(field).toBeDefined();
expect(field.id).toEqual('field-id');
expect(field.value).toEqual('field-value');
});
done();
}, 200);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit {
onBlur() {
setTimeout(() => {
this.flushValue();
this.checkVisibility(this.field);
}, 200);
}

Expand Down Expand Up @@ -108,6 +109,7 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit {
if (item) {
this.field.value = item.id;
this.value = item.name;
this.checkVisibility(this.field);
}
if (event) {
event.preventDefault();
Expand Down