Advertisement:

Author Topic: Show Country etc if has item(s)  (Read 540 times)

sirjones

  • Full Member
  • ***
  • Posts: 102
Show Country etc if has item(s)
« on: March 22, 2017, 10:14:47 pm »
Hi There..

Code: [Select]
CountryStats::newInstance()->calculateNumItems() to the Country (and similar with it to Region, City) Dropdown will showing Country list if has item(s)  in the first visit 
but in the next action whenever we select the Country it seem goes to resetting all the Region and City, so how to keep the Region, City (without resetting) remains displayed if has item(s)?

thanks in advance

sirjones

  • Full Member
  • ***
  • Posts: 102
Re: Show Country etc if has item(s)
« Reply #1 on: March 23, 2017, 09:15:11 am »
example code that i have cacthed as following

Code: [Select]
function countries_chosen($name, $id, $label, $value=NULL){
    $name = osc_esc_html($name);
    $id = osc_esc_html($id);
    $label = osc_esc_html($label);
$aCountries = Country::newInstance()->listAll();
if(count($aCountries) > 0 ) {
$html  = '<select name="'.$name.'" id="'.$id.'">';
$html .= '<option value="">'.$label.'</option>';
foreach($aCountries as $country) {
if($value == $country['pk_c_code']) $selected = 'selected="selected"'; else $selected = '';
if(CountryStats::newInstance()->calculateNumItems($country['pk_c_code'])>0) {
$html .= '<option value="'. $country['pk_c_code'].'" '.$selected.'>'. $country['s_name'].'</option>';
}
}
$html .= '</select>';
}
echo $html;
}

and

Code: [Select]
    function chosen_region_select() {
        View::newInstance()->_exportVariableToView('list_regions', Search::newInstance()->listRegions('%%%%', '>=', 'region_name ASC') ) ;

        if( osc_count_list_regions() > 0 ) {
            echo '<select name="sRegion" data-placeholder="' . __('Select a region...', 'twitter') .'" style="width:auto" class="form-control chosen-select">' ;
            echo '<option></option>' ;
            while( osc_has_list_regions() ) {
                 if(RegionStats::newInstance()->calculateNumItems($osc_region_id())>0) {
                echo '<option value="' . osc_list_region_id() . '">' . osc_list_region_name() . '</option>' ;
            }
            echo '</select>' ;
        }
        View::newInstance()->_erase('list_regions') ;
    }

How to resolve it or wicth codes need to change? thankyou

sirjones

  • Full Member
  • ***
  • Posts: 102
Re: Show Country etc if has item(s)
« Reply #2 on: April 14, 2017, 05:18:07 pm »
when I use osclasswizard theme, I see the code related to the location drop down select, in js / main.js file as follows:

Code: [Select]
$("#sCountry").on("change",function(){var e=$("#sRegionSelect").text(),i=$("#sCitySelect").text();$("#sRegion").next().children(".select-box-label").text(e),$("#sCity").next().children(".select-box-label").text(i);var t=$(this).val(),s=osclasswizards.base_url+"?page=ajax&action=regions&countryId="+t,o='<option value="" id="sRegionSelect">'+e+"</option>";""!=t&&$.ajax({type:"POST",url:s,dataType:"json",success:function(e){var i=e.length;if(i>0){for(key in e)o+='<option value="'+e[key].pk_i_id+'">'+e[key].s_name+"</option>";$("#sRegion").html(o)}}})}),$("#sRegion").on("change",function(){var e=$("#sCitySelect").text();$("#sCity").next().children(".select-box-label").text(e);var i=$(this).val(),t=osclasswizards.base_url+"?page=ajax&action=cities&regionId="+i,s='<option value="" id="sCitySelect">'+e+"</option>";""!=i&&$.ajax({type:"POST",url:t,dataType:"json",success:function(e){var i=e.length;if(i>0){for(key in e)s+='<option value="'+e[key].s_name+'">'+e[key].s_name+"</option>";$("#sCity").empty().html(s)}}})}),
 looks like the following url post is the most decisive,

Code: [Select]
s=osclasswizards.base_url+"?page=ajax&action=regions&countryId="+t,o='<option value="" id="sRegionSelect">'+e+"</option>";""!=t&&$.ajax({type:"POST",url:s,dataType:"json",success:function(e){var i=e.length;if(i>0){for(key in e)o+='<option value="'+e[key].pk_i_id+'">'+e[key].s_name+"</option>";AND
Code: [Select]
t=osclasswizards.base_url+"?page=ajax&action=cities&regionId="+i,s='<option value="" id="sCitySelect">'+e+"</option>";""!=i&&$.ajax({type:"POST",url:t,dataType:"json",success:function(e){var i=e.length;where the destination file processing ?

so that only displays the dropdown location if has ad/item
« Last Edit: April 14, 2017, 05:21:37 pm by sirjones »