I am working with an array of objects that have multiple properties. Each object has an object.comment
property, which may either be filled with a string ('comment' : 'comment text'
), or empty ('comment' : ''
).
To display the results, I use ng-repeat as shown below:
<div class="row msf-row"
ng-repeat="record in filteredRecords = (recordlist | filter:dateFilter | filter: search )"
>
My goal is to add a checkbox filter that will show only the results where the object.comment
property is filled when the checkbox is checked, and show all results when it is unchecked.
Here's my current filter setup:
<form role="form">
<div class="form-group col-md-3">
<input type='daterange'
placeholder="Date range"
class="form-control"
format="DD/MM/YYYY"
ng-model="dates"
ranges="ranges" />
</div>
<div class="form-group col-md-1">
<input class="form-control" placeholder="Time" ng-model="search.time">
</div>
<div class="form-group col-md-1">
<input class="form-control" placeholder="Car" ng-model="search.car">
</div>
<div class="form-group col-md-2">
<input class="form-control" placeholder="Driver" ng-model="search.driver">
</div>
<div class="form-group col-md-2">
<input class="form-control" placeholder="From" ng-model="search.from">
</div>
<div class="form-group col-md-2">
<input class="form-control" placeholder="Destination" ng-model="search.destination">
</div>
<div class="form-group col-md-1">
<input class="form-control" placeholder="Pax" ng-model="search.pax">
</div>
<div class="col-md-1">
<div class="checkbox">
<label>
<input type="checkbox"
ng-model="search.cancelled"
ng-change="search.cancelled = search.cancelled ? true : undefined"
> Cancelled
</label>
</div>
</div>
<div class="col-md-2">
<div class="checkbox">
<label>
<input type="checkbox"
ng-model="search.comment"
ng-change="search.comment = search.comment ? true : undefined"
> Commented records
</label>
</div>
</div>
</form>
While I have successfully implemented a filter based on whether the object.cancelled
property is true or false, I am struggling to do the same for the object.comment
property being empty or containing a string.
Could anyone provide some assistance?