Advertisement:

Author Topic: pre-Selected items  (Read 1847 times)

bstruik

  • Newbie
  • *
  • Posts: 27
pre-Selected items
« on: December 09, 2014, 07:33:17 pm »
Can someone help me with this?
I use the car plugin .. but when i post a ad some fields are already on fuel (diesel), transmission etc... how can make this select-able?

How to make it that the user MUST select this field? .. and how to make this fields required?

Thanks
« Last Edit: December 11, 2014, 04:28:48 pm by bstruik »

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: pre-Selected items
« Reply #1 on: December 09, 2014, 08:26:00 pm »

bstruik

  • Newbie
  • *
  • Posts: 27
Re: pre-Selected items
« Reply #2 on: December 11, 2014, 04:29:26 pm »
I read the thing about removing and adding some fields... but still no luck on this: when i post a ad some fields are already on fuel (diesel), transmission etc... how can make this select-able?

luka93

  • Jr. Member
  • **
  • Posts: 82
Re: pre-Selected items
« Reply #3 on: December 11, 2014, 05:46:02 pm »
+1

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: pre-Selected items
« Reply #4 on: December 11, 2014, 11:38:19 pm »
Hi,

You could just change the plugin code (item-edit.php), but here is an external solution that should work even in the case the plugin is upgraded.

Add this at the very bottom of your theme functions.php (take care not to leave blank lines after this):

Code: [Select]
<?php
function cust_ca_selects_default_option() { ?>


    <script type="text/javascript">
        $("select#transmission").prepend('<option value="" selected="selected"><?php _e('Select transmission type''cars_attributes'); ?></option>');
        $("select#fuel").prepend('<option value="" selected="selected"><?php _e('Select fuel type''cars_attributes'); ?></option>');
        $("select#seller").prepend('<option value="" selected="selected"><?php _e('Select seller type''cars_attributes'); ?></option>');
    </script>
<?php }

osc_add_hook('item_form''cust_ca_selects_default_option'1);
osc_add_hook('item_edit''cust_ca_selects_default_option'1);
?>

Regards

bstruik

  • Newbie
  • *
  • Posts: 27
Re: pre-Selected items
« Reply #5 on: December 15, 2014, 05:31:21 pm »
Dear teseo ... i cant get this to work. Let me past a bit of my functions.php. this is the end of my functions.php file:

function boxer_sidebar_category_search($catId = null)
{
    $aCategories = array();
    if($catId==null) {
        $aCategories[] = Category::newInstance()->findRootCategoriesEnabled();
    } else {
        // if parent category, only show parent categories
        $aCategories = Category::newInstance()->toRootTree($catId);
        end($aCategories);
        $cat = current($aCategories);
        // if is parent of some category
        $childCategories = Category::newInstance()->findSubcategoriesEnabled($cat['pk_i_id']);
        if(count($childCategories) > 0) {
            $aCategories[] = $childCategories;
        }
    }

    if(count($aCategories) == 0) {
        return "";
    }

    boxer_print_sidebar_category_search($aCategories, $catId);
}

function boxer_print_sidebar_category_search($aCategories, $current_category = null, $i = 0)
{
    $class = '';
    if(!isset($aCategories[$i])) {
        return null;
    }

    if($i===0) {
        $class = 'class="category"';
    }

    $c   = $aCategories[$i];
    $i  ;
    if(!isset($c['pk_i_id'])) {
        echo '<ul '.$class.'>';
        if($i==1) {
            echo '<li><a href="'.osc_esc_html(osc_update_search_url(array('sCategory'=>null, 'iPage'=>null))).'">'.__('All categories', 'boxer')."</a></li>";
        }
        foreach($c as $key => $value) {
    ?>
            <li>
                <a id="cat_<?php echo osc_esc_html($value['pk_i_id']);?>" href="<?php echo osc_esc_html(osc_update_search_url(array('sCategory'=> $value['pk_i_id'], 'iPage'=>null))); ?>">
                <?php if(isset($current_category) && $current_category == $value['pk_i_id']){ echo '<strong>'.$value['s_name'].'</strong>'; }
                else{ echo $value['s_name']; } ?>
                </a>

            </li>
    <?php
        }
        if($i==1) {
        echo "</ul>";
        } else {
        echo "</ul>";
        }
    } else {
    ?>
    <ul <?php echo $class;?>>
        <?php if($i==1) { ?>
        <li><a href="<?php echo osc_esc_html(osc_update_search_url(array('sCategory'=>null, 'iPage'=>null))); ?>"><?php _e('All categories', 'boxer'); ?></a></li>
        <?php } ?>
            <li>
                <a id="cat_<?php echo osc_esc_html($c['pk_i_id']);?>" href="<?php echo osc_esc_html(osc_update_search_url(array('sCategory'=> $c['pk_i_id'], 'iPage'=>null))); ?>">
                <?php if(isset($current_category) && $current_category == $c['pk_i_id']){ echo '<strong>'.$c['s_name'].'</strong>'; }
                      else{ echo $c['s_name']; } ?>
                </a>
                <?php boxer_print_sidebar_category_search($aCategories, $current_category, $i); ?>
            </li>
        <?php if($i==1) { ?>
        <?php } ?>
      <?php
function cust_ca_selects_default_option() { ?>

    <script type="text/javascript">
        $("select#transmission").prepend('<option value="" selected="selected"><?php _e('Select transmission type', 'cars_attributes'); ?></option>');
        $("select#fuel").prepend('<option value="" selected="selected"><?php _e('Select fuel type', 'cars_attributes'); ?></option>');
        $("select#seller").prepend('<option value="" selected="selected"><?php _e('Select seller type', 'cars_attributes'); ?></option>');
    </script>
<?php }

osc_add_hook('item_form', 'cust_ca_selects_default_option', 1);
osc_add_hook('item_edit', 'cust_ca_selects_default_option', 1);
?>
    </ul>
<?php
    }
}

/**

CLASSES

*/
class boxerBodyClass
{
    /**
    * Custom Class for add, remove or get body classes.
    *
    * @param string $instance used for singleton.
    * @param array $class.
    */
    private static $instance;
    private $class;

    private function __construct()
    {
        $this->class = array();
    }

    public static function newInstance()
    {
        if (  !self::$instance instanceof self)
        {
            self::$instance = new self;
        }
        return self::$instance;
    }

    public function add($class)
    {
        $this->class[] = $class;
    }
    public function get()
    {
        return $this->class;
    }
}

/**

HELPERS

*/
if( !function_exists('osc_uploads_url') ){
    function osc_uploads_url($item = ''){
        return osc_base_url().'oc-content/uploads/'.$item;
    }
}

if( !function_exists('osc_uploads_url') ){
    function osc_uploads_url($item = ''){
        return osc_base_url().'oc-content/uploads/'.$item;
    }
}

function cust_format_date_with_time($date, $dateformat = null) {
    if($dateformat==null) {
        $dateformat = osc_date_format();
    }
    $ampm = array('AM' => __('AM'), 'PM' => __('PM'), 'am' => __('am'), 'pm' => __('pm'));
    $time = strtotime($date);
    $dateformat = preg_replace('|(?<!\\\)A|', osc_escape_string($ampm[date('A', $time)]), $dateformat);
    $dateformat = preg_replace('|(?<!\\\)a|', osc_escape_string($ampm[date('a', $time)]), $dateformat);
    return date(osc_time_format(), $time);
}
?>