<form id="filterForm" action="">
select:
<input id="filterSelect" size="50" type="text" list="selects" name="select" >
<datalist id="selects">
<option value="Name">Name only</option>
<option value="Name, Short Description">Name and Short Description</option>
<option value="Name, Short Description, Iteration">With Iteration</option>
<option value="Name, Short Description, Iteration, Creation Date">With Iteration and Creation Date</option>
</datalist>
${datalistselects}
where:
<input id="filterWhere" size="50" type="text" list="wheres" name="where">
<datalist id="wheres">
<option value="$<Iteration>=[Facade]">Facade</option>
<option value="$<Iteration>=[Filled]">Filled</option>
<option value="$<Iteration>=[Finished]">Finished</option>
</datalist>${datalistwhere}
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
<script>
AJS.toInit(function() {
var urlParams = new URLSearchParams(window.location.search);
var originalSelect = urlParams.get('filtered:select');
var originalWhere = urlParams.get('customWhere');
$("#filterSelect").val(originalSelect);
$("#filterWhere").val(originalWhere);
function appendToQueryString( queryString, queryParam ) {
if(queryString.trim())
{
queryString=queryString + "&" + queryParam;
}
else
{
queryString="?"+queryParam;
}
return queryString;
};
$('#filterForm').submit(function(evt) {
evt.preventDefault();
var tableId = "filtered";
var $initialWhere = "${initialwhere}"
var $select = $('#filterSelect').val();
var $where = $('#filterWhere').val();
console.debug($select);
console.debug($where);
var $queryString="";
if ($select.trim())
{
var $encodedSelect = encodeURI($select);
var $selectQueryParam = tableId + ":"+"select"+"="+$encodedSelect;
$queryString=appendToQueryString($queryString, $selectQueryParam);
}
if ($where.trim())
{
var $encodedCustomWhere = encodeURI($where);
var $customWhereQueryParam = "customWhere"+"="+$encodedCustomWhere;
var $encodedWhere = encodeURI($initialWhere + " AND " + $where);
var $whereQueryParam = tableId + ":"+"where"+"="+$encodedWhere;
$queryString = appendToQueryString($queryString, $whereQueryParam);
$queryString = appendToQueryString($queryString, $customWhereQueryParam );
}
$action = window.location.href.split('?')[0] + $queryString;
$('#filterForm').attr('action', $action);
console.debug($action);
window.location.href=$action;
});
});
</script> |