I am using AJAX to auto populate a Sub Categories select box, its contents depend on whats selected in the main Categories Select Box. It seems when I select a main Category and something is returned back, the Sub Category select vanishes and its replaced by an IFRAME of the homepage/index.php.
// INCLUDED IN THE MODULE CONFIG
'js_controller'=>'ProductController'
// THE ACTUAL ProductController.js
fuel.controller.ProductController = jqx.createController(fuel.controller.BaseFuelController, {
init: function(initObj){
this._super(initObj);
},
items : function(){
// call parent
fuel.controller.BaseFuelController.prototype.items.call(this);
//fuel.controller.BaseFuelController.prototype.items();
var _this = this;
$('#product_subcategory').change(function(e){
$('#form_table').submit();
});
},
add_edit : function(){
// call parent
fuel.controller.BaseFuelController.prototype.add_edit.call(this);
var origParentId = $('#product_subcategory').val();
var id = 5;
$('#product_category').change(function(e){
var category=$('#product_category').val();
category=category.replace(' ','_');
var path = jqx.config.basePath + '/products/getsubcat/' + category;
$('#product_subcategory').parent().load(path);
});
},
upload : function(){
this._notifications();
this._initAddEditInline($('#form'));
}
});
// THE MODEL
// Show Subcats
$fields['product_subcategory'] = array(
'label'=>'Product Subcategory',
'type'=>'select',
'options'=>$this->getsubcats($values['product_category'],$values['product_subcategory']),
'order' => '12'
);
// THE FUNCTION WITHIN THE MODEL
function getsubcats($cat,$sub) {
$subcats=array();
$q=$this->db->get_where('fuel_product_categories',array('category_name'=>$cat));
foreach($q->result() as $row) {
if($sub!=$row->subcategory_name) {
$subcats[$row->subcategory_name]=$row->subcategory_name;
}
}
$subcats[$sub]=$sub;
return $subcats;
}
All the ID's are set correctly in the fields!
Thanks
Comments
Sorry i dont understand...
Any routes set that may redirect? I'm assuming you have a custom fuel controller of products with a getsubcats method? Can we see that?