I've built a cascading form with dependent form fields, e.g.
a selected list of manufactures
$fields['make_id'] = array('label' => 'Make', 'type' => 'select', 'options' => $options, 'first_option' => 'Select one...');
the list of products depends on the manufacturer
['model_id'] = array('type' => 'dependent', 'depends_on' => 'make_id', 'url' => fuel_url('models/ajax/options'), 'multiple' => FALSE);
Then the attributes of the product are loaded
$fields['body_type'] = array('type' => 'select',
'js' => '$(function(){
$(document).on("change", "#model_id", function(e){
var url = "'.fuel_url('body_types/ajax/options').'";
$.get(url, {model_id: $(this).val()}, function(html){
$("#body_type").html(html);
});
});
$("#model_id").trigger("change");
});
');
.....
I've specified the js function for the attributes as the dependent field type has been causing a js problem whereby the image field buttons weren't loading (no console error).
The form works find when creating products, but doesn't load the attributes when trying to edit a product.
I can't figure out where the issue is, any pointers would be gratefully received.
P.S. everything works fine when there is only one manufacturer
Comments
https://github.com/daylightstudio/FUEL-CMS/tree/develop
It seems that it can't handle the cascading dependency. manufacture determines products which intern determines product attributes.
It all works fine when there is one manufacturer.
the create function now works, edit is still and issue
I've got the fields working as I want them.
In the form_fields function I pick up on the $values to determine if its edit or create. I guess there's a eloquent fuel way to do this that I've not found yet. So:
load manufacturer list
$fields['product_id'] = array('type' => 'dependent', 'depends_on' => 'make_id', 'url' => fuel_url('products/ajax/options'), 'multiple' => FALSE);
if(!$values){
$fields['body_type'] = array('type' => 'dependent', 'depends_on' => 'model_id', 'url' => fuel_url('body_types/ajax/options'), 'multiple' => FALSE);
$fields['body_type']['order'] = "12";
} else {
$this->db->select('body_types.id, body_types.option');
$this->db->join('model_body_types', 'model_body_types.option_id = body_types.id','LEFT');
$ST2K_options = $this->db->get_where('body_types', array('model_id' => $values['model_id'], 'active' => 'yes'))->result();
$options = array();
foreach ($ST2K_options as $ST2K_option){
$options[$ST2K_option->id]=$ST2K_option->option;
}
$fields['body_type'] = array('label' => 'Body Type', 'type' => 'select', 'options' => $options);
}
Thanks