-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(md-autocomplete): add autocomplete, closes #209
- Loading branch information
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {bindable, customAttribute} from 'aurelia-templating'; | ||
import {inject} from 'aurelia-dependency-injection'; | ||
import {fireEvent} from '../common/events'; | ||
|
||
@customAttribute('md-autocomplete') | ||
@inject(Element) | ||
export class MdAutoComplete { | ||
input = null; | ||
@bindable() values = {}; | ||
|
||
constructor(element) { | ||
this.element = element; | ||
} | ||
|
||
attached() { | ||
if (this.element.tagName.toLowerCase() === 'input') { | ||
this.input = this.element; | ||
} else if (this.element.tagName.toLowerCase() === 'md-input') { | ||
this.input = this.element.au.controller.viewModel.input; | ||
} else { | ||
throw new Error('md-autocomplete must be attached to either an input or md-input element'); | ||
} | ||
this.refresh(); | ||
} | ||
|
||
detached() { | ||
// remove .autocomplete-content children | ||
$('.autocomplete-content', this.element).off('click'); | ||
$('.autocomplete-content', this.element).remove(); | ||
} | ||
|
||
refresh() { | ||
this.detached(); | ||
$(this.input).autocomplete({ | ||
data: this.values | ||
}); | ||
$('.autocomplete-content', this.element).on('click', () => { | ||
fireEvent(this.input, 'change'); | ||
}); | ||
} | ||
|
||
valuesChanged(newValue) { | ||
this.refresh(); | ||
} | ||
} |
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
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
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