I'm struggling to implement two filters using ng-hide. Check out this fiddle where I've showcased the issue: http://jsfiddle.net/czPf6/2/ I have a piece of code that dynamically selects which filter to use based on input values from an input box and a select box:
function applySearchFilter() {
var filterCategory = $scope.filters.cat.toLowerCase();
//console.log(filterCategory);
var category = $scope.friend.job.toLowerCase();
//console.log(category);
var filter = $scope.filters.name.toLowerCase();
//console.log(filter);
var name = $scope.friend.name.toLowerCase();
console.log(name + " " + category);
console.log("filter:" + filter + "/category:" + filterCategory);
if($scope.filters.name == "" && $scope.filters.cat !== ""){
var isCategory = (filterCategory == category);
console.log(isCategory + "1st");
$scope.isExcludedByFilter = ! isCategory;
console.log($scope.isExcludedByFilter);
} else if($scope.filters.name !=="" && $scope.filters.cat == ""){
var isSubstring = ( name.indexOf( filter ) !== -1 );
console.log(isSubstring + "2nd");
$scope.isExcludedByFilter = ! isSubstring;
console.log($scope.isExcludedByFilter);
} else if($scope.filters.name !=="" && $scope.filters.cat !==""){
var isCategory = (filterCategory == category);
var isSubstring = ( name.indexOf( filter ) !== -1 );
console.log(isCategory + "3rd");
console.log(isSubstring + "3rd");
$scope.isExcludedByFilter = ! isSubstring && ! isCategory;
console.log($scope.isExcludedByFilter);
}
The log statements display the expected values, but the filter only functions when both input fields contain a value. What could be the issue in my implementation?