diff --git a/includes/custom-field-ajuts-filter-function-frontend.php b/includes/custom-field-ajuts-filter-function-frontend.php index b5d4fd4..1d275a7 100644 --- a/includes/custom-field-ajuts-filter-function-frontend.php +++ b/includes/custom-field-ajuts-filter-function-frontend.php @@ -60,15 +60,10 @@ if( ! function_exists( 'ofisuport_ajuts_filters_form' ) ):
$choicelabel ) { ?> -
- - value="" - name="" /> - -
+
+ value="" /> + +
@@ -106,42 +101,56 @@ if( ! function_exists( 'ofisuport_ajuts_filters_form' ) ): // vars var url = ''; args = {}; - + var appendtoURL = ''; + var eachfiltered = ''; + var valueschecked = ''; + // loop over filters $('#archive-filters .filter').each(function(){ - urldos = url; - // vars - var filteredajuts = $(this).data('filter'), - vals = [], - allvalueschecked = []; - // find checked inputs - $(this).find('input:checked').each(function(){ - vals.push( $(this).val() ); - var thisvaluechecked = $(this).val(); - urldos += filteredajuts; - }); - - // append to args - args[ filteredajuts ] = vals.join(','); - alert( filteredajuts +'=' +args[ filteredajuts ]); + // check if is first appearance of each + if( eachfiltered != $(this).data('filter') ){ + + // save already calculated field=val01,val02,val03 + appendtoURL += eachfiltered +'=' +valueschecked +'&'; + // remove last ',' + appendtoURL = appendtoURL.slice(0, -1); + // start new fieldname filtered + eachfiltered = $(this).data('filter'); + // reset values + valueschecked = ''; + // find checked inputs + $(this).find('input:checked').each(function(){ + // if not empty save value and , + if( $(this).val() != '' ){ + valueschecked = $(this).val() + ','; + } + }); + } else { + // we have previous values checked + // find checked inputs + if( $(this).val() != '' ){ + // if not empty append value and , + $(this).find('input:checked').each(function(){ + valueschecked += $(this).val() + ','; + }); + } + }; }); + // save last cycled filtered value already calculated field=val01,val02,val03 + appendtoURL += eachfiltered +'=' +valueschecked +'&'; + + // remove last & + appendtoURL = url.slice(0, -1); + // update url url += '?'; - // loop over args - $.each(args, function( name, value ){ - url += name + '=' + value + '&'; - }); - - - // remove last & - url = url.slice(0, -1); // reload page //$('#archive-filters button').on('click', function () { - alert( "estoy en: " +url ); + alert( "estoy en: " +url +appendtoURL); //window.location.replace( url ); //});