Skip to content

Instantly share code, notes, and snippets.

@geraldhumphries
Created December 19, 2015 18:26
Show Gist options
  • Save geraldhumphries/ba159d2ea93c41d8054a to your computer and use it in GitHub Desktop.
Save geraldhumphries/ba159d2ea93c41d8054a to your computer and use it in GitHub Desktop.
JHipster autocomplete combobox
$scope.loadOtherEntities = function(searchQuery) {
if (searchQuery){
OtherEntitySearch.query({query: '*' + searchQuery + '*'}, function(result) {
$scope.otherEntities = result;
}, function(response) {
if(response.status === 404) {
$scope.otherEntities = OtherEntity.query({isActive: true});
}
});
} else {
$scope.otherEntities = OtherEntity.query({isActive: true});
}
};
<div class="form-group">
<label class="control-label" translate="jhApp.entity.otherEntity">otherEntity</label>
<ui-select reset-search-input="false" ng-model="entity.otherEntity">
<ui-select-match allow-clear="true">
<span ng-bind="$select.selected.name"></span>
</ui-select-match>
<ui-select-choices refresh="loadOtherEntities($select.search)" refresh-delay="200"
repeat="item in (otherEntities) track by item.id">
<span ng-bind="item.name"></span>
</ui-select-choices>
</ui-select>
</div>
@sw-enthusiast
Copy link

@geraldhumphries Thanks for your response. I will try it and let you know.

@sw-enthusiast
Copy link

sw-enthusiast commented Dec 28, 2016

The requirement changed due to the complexity. Now they asked me to filter the pre populated results based on the query parameter that is selected on the top drop down.

Here is how it looks
image

The requirement is when the user selects the country 'US' I have to show only the states in 'US' in the States drop down. Please let me know if you have any sample projects in this scenario using Jhipster.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment