0

I'm using OSClass to build a site which will be holding several classified ads. Unfortunately some scripts don't work well with Firefox/IE so I need to track those errors down.

The script is supposed to be like this:

  1. You choose category for your ad
  2. When you've chosen the category, the script checks for sub-categories and will add another box where you choose your sub-category.

Here's the .js file:

var is_loading = true ;

function fill_subcategory_select ( id ) {
var category    = $("select.category") ;
var subcategory = $("select.subcategory") ;

// reset subcategory select
subcategory.html("") ;

console.log(twitter_theme.categories["id_" + id]) ;
// check that the category has subcategories
if( typeof twitter_theme.categories["id_" + id] === "undefined" ) {
    console.log("[fill_subcategory_select] hide subcategory") ;
    subcategory.append( $("<option>").attr('value', id) ) ;
    subcategory.css("display", "none") ;
    $("select.subcategory").trigger('change') ;
    return true;
}

subcategory.html()
subcategory.append( $("<option>").attr('value', id).html(twitter_theme.text_select_subcategory) ) ;
$.each(twitter_theme.categories["id_" + id], function(key, value) {
    console.log("[fill_subcategory_select] subcategory { id: " + value.id + ", slug: " + value.slug + ", name: " + value.name + " }") ;
    subcategory.append( $("<option>").attr('value', value.id).html(value.name) ) ;
}) ;
subcategory.css("display", "") ;
return true;
}

And here's from the actual form:

<script type="text/javascript">
        twitter_theme.text_select_subcategory = "<?php _e('Select a subcategory...', 'twitter_bootstrap') ; ?>" ;
        twitter_theme.category_selected_id    = "<?php echo item_selected_category_id() ; ?>" ;
        twitter_theme.subcategory_selected_id = "<?php echo item_selected_subcategory_id() ; ?>" ;
</script>

<!-- category input -->
<div class="clearfix">
<label><?php _e('Category', 'twitter_bootstrap') ; ?></label>
<div class="input">
<?php item_category_select( __('Select a category', 'twitter_bootstrap') ) ; ?>
</div>
</div>
<!-- category input end -->

What happens in Firefox is that when you choose a category the sub-category list won't show at all, which destroys the functionality of the register form because it gives the error message: "Invalid category".

random
  • 9,774
  • 10
  • 66
  • 83
MstrQKN
  • 836
  • 10
  • 28

1 Answers1

2

Finally, I've found the problem. The issue was in item_category_select_js() function. You can find this function in ./twitter_bootstrap/functions.php. Here is the new code:

function item_category_select_js() {
    ?>
    <script type="text/javascript">
        twitter_theme.categories = {} ;
    <?php
    $aCategories = osc_get_categories() ;
    foreach($aCategories as $category) {
        if( is_array($category['categories']) && (count($category['categories']) > 0) ) {
            echo 'twitter_theme.categories.id_' . $category['pk_i_id'] . ' = {' . PHP_EOL ;
            for($i = 0; $i < count($category['categories']); $i++) {
                echo $category['categories'][$i]['pk_i_id'] . ': { id: ' . $category['categories'][$i]['pk_i_id'] . ', slug: "' . addslashes($category['categories'][$i]['s_slug']) . '", name: "' . addslashes($category['categories'][$i]['s_name']) . '"' ;
                if( $i == (count($category['categories']) - 1) ) {
                    echo '}' . PHP_EOL ;
                } else {
                    echo '} ,' . PHP_EOL ;
                }
            }
            echo '} ;' ;
        } else {
            echo 'twitter_theme.categories.' . $category['s_slug'] . ' = { } ;' . PHP_EOL  ;
        }
    }
    ?>
    </script>
    <?php
}

It has been fixed in last version (1.2.1). You can download from here: https://sourceforge.net/projects/osclass/files/Themes/twitter/

Juan Ramón
  • 615
  • 1
  • 5
  • 19