1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

Disable search submit until a search string is present

This commit is contained in:
mabashian 2018-07-30 10:22:36 -04:00
parent 681d64c96f
commit ba075ce5dd
4 changed files with 43 additions and 36 deletions

View File

@ -13,7 +13,7 @@
<span class="input-group-btn">
<button class="btn at-ButtonHollow--default at-Input-button"
ng-click="vm.submitSearch()"
ng-disabled="vm.disabled"
ng-disabled="vm.disabled || !vm.value || vm.value === ''"
type="button">
<i class="fa fa-search"></i>
</button>

View File

@ -76,10 +76,15 @@
z-index: 1;
}
.SmartSearch-searchButton:hover {
.SmartSearch-searchButton:not(.SmartSearch-searchButton--disabled):hover {
background-color: @default-tertiary-bg;
}
.SmartSearch-searchButton--disabled {
cursor: not-allowed;
opacity: 0.65;
}
.SmartSearch-flexContainer {
display: flex;
width: 100%;

View File

@ -174,43 +174,45 @@ function SmartSearchController (
};
$scope.addTerms = terms => {
const { singleSearchParam } = $scope;
const unmodifiedQueryset = _.clone(queryset);
if (terms && terms !== "") {
const { singleSearchParam } = $scope;
const unmodifiedQueryset = _.clone(queryset);
const searchInputQueryset = qs.getSearchInputQueryset(terms, isFilterableBaseField, isRelatedField, isAnsibleFactField, singleSearchParam);
queryset = qs.mergeQueryset(queryset, searchInputQueryset, singleSearchParam);
const searchInputQueryset = qs.getSearchInputQueryset(terms, isFilterableBaseField, isRelatedField, isAnsibleFactField, singleSearchParam);
queryset = qs.mergeQueryset(queryset, searchInputQueryset, singleSearchParam);
// Go back to the first page after a new search
delete queryset.page;
// Go back to the first page after a new search
delete queryset.page;
// https://ui-router.github.io/docs/latest/interfaces/params.paramdeclaration.html#dynamic
// This transition will not reload controllers/resolves/views but will register new
// $stateParams[searchKey] terms.
if (!$scope.querySet) {
transitionSuccessListener();
$state.go('.', { [searchKey]: queryset })
.then(() => {
// same as above in $scope.remove. For some reason deleting the page
// from the queryset works for all lists except lists in modals.
delete $stateParams[searchKey].page;
listenForTransitionSuccess();
});
// https://ui-router.github.io/docs/latest/interfaces/params.paramdeclaration.html#dynamic
// This transition will not reload controllers/resolves/views but will register new
// $stateParams[searchKey] terms.
if (!$scope.querySet) {
transitionSuccessListener();
$state.go('.', { [searchKey]: queryset })
.then(() => {
// same as above in $scope.remove. For some reason deleting the page
// from the queryset works for all lists except lists in modals.
delete $stateParams[searchKey].page;
listenForTransitionSuccess();
});
}
qs.search(path, queryset)
.then(({ data }) => {
if ($scope.querySet) {
$scope.querySet = queryset;
}
$scope.dataset = data;
$scope.collection = data.results;
$scope.$emit('updateDataset', data);
})
.catch(() => revertSearch(unmodifiedQueryset));
$scope.searchTerm = null;
generateSearchTags();
}
qs.search(path, queryset)
.then(({ data }) => {
if ($scope.querySet) {
$scope.querySet = queryset;
}
$scope.dataset = data;
$scope.collection = data.results;
$scope.$emit('updateDataset', data);
})
.catch(() => revertSearch(unmodifiedQueryset));
$scope.searchTerm = null;
generateSearchTags();
};
// remove tag, merge new queryset, $state.go
$scope.removeTerm = index => {

View File

@ -7,7 +7,7 @@
<input class="SmartSearch-input" ng-model="searchTerm" placeholder="{{searchPlaceholder}}"
ng-disabled="disableSearch">
</form>
<div type="submit" class="SmartSearch-searchButton" ng-disabled="!searchTerm" ng-click="addTerms(searchTerm)">
<div type="submit" class="SmartSearch-searchButton" ng-class="{'SmartSearch-searchButton--disabled': !searchTerm || searchTerm === ''}" ng-click="addTerms(searchTerm)">
<i class="fa fa-search"></i>
</div>
</div>