i have three dependent fields which when you create content works ok. The problem is when you edit the content and try to change any of the dependent fields they don't update each other could you please advice.
here is a snipit from the model to assist
if (!$values) {
$fields['offer_model_id'] = array('type' => 'dependent', 'depends_on' => 'offer_range_id', 'url' => fuel_url('Cap_model/ajax/options'), 'order' => 107, 'label' => 'Model', 'first_option' => 'Select one...');
$fields['offer_deriviative'] = array('type' => 'dependent', 'depends_on' => 'offer_model_id', 'url' => fuel_url('Cap_derivative/ajax/options'), 'order' => 108, 'label' => 'Derivative', 'first_option' => 'Select one...');
} else {
$this->db->select('CMod_Code, CMod_Name');
$model_options = $this->db->get_where('CAPMod', array('CRan_Code' => $values['offer_range_id']))->result();
$moptions = array();
$moptions[] = 'Select one...';
foreach ($model_options as $model_option) {
$moptions[$model_option->CMod_Code] = $model_option->CMod_Name;
}
$this->db->select('CDer_ID, CDer_Name');
$derivative_options = $this->db->get_where('CAPDer', array('CMod_Code' => $values['offer_model_id']))->result();
$deroptions = array();
$deroptions[] = 'Select one...';
foreach ($derivative_options as $derivative_option) {
$deroptions[$derivative_option->CDer_ID] = $derivative_option->CDer_Name;
}
$fields['offer_model_id'] = array('type' => 'select', 'options' => $moptions, 'order' => 107, 'label' => 'Model');
$fields['offer_deriviative'] = array('type' => 'select', 'options' => $deroptions, 'order' => 108, 'label' => 'Derivative');
}
Comments
1. Does it work when using only one dependent field?
2. What version of FUEL (you can check in fuel/modules/fuel/config/fuel_constants.php)?
3. In the fuel/modules/fuel/assets/js/fuel/custom_fields.js around line 1444 (depending on the version of FUEL), what does the value of "origValue" (e.g. console.log(origValue))?
1. yes it works for one dependent field
2. version 1.4
3. the value returned of origValue is from the second dependent field. i have two further field that need to update. I removed the if statement so they where all using the dependent field code just to see but the last two dependent fields do not remember there values.
looking at the code frontend i have spotted the the select fields do have there original values here
<div class="orig_value" style="display: none;">"74738"</div>
but they are not selected on this value. And the fields do not have any values in the select boxes to choose$(function () { // check to see if there is a manufacturer dropdown if($("#CMan_Code").length){ // when model dropdown loaded get its original value and get the dropdown values $('#offer_model_id').ready(function () { $.ajax({ url: $('#offer_model_id').data('ajax_url'), type: 'GET', data: { offer_range_id : $('#offer_range_id').closest('.field, .value').find('.orig_value').text().replace(/\"/g, ""), }, success: function (data) { $('#offer_model_id').html(data); var selected = $('#offer_model_id').closest('.field, .value').find('.orig_value').text().replace(/\"/g, ""); $('#offer_model_id').val(selected); } }); }); // when the derivative has loaded get the original value and the dropdown values $('#offer_deriviative').ready(function () { $.ajax({ url: $('#offer_deriviative').data('ajax_url'), type: 'GET', data: { offer_model_id : $('#offer_model_id').closest('.field, .value').find('.orig_value').text().replace(/\"/g, ""), }, success: function (data) { $('#offer_deriviative').html(data); var selected = $('#offer_deriviative').closest('.field, .value').find('.orig_value').text().replace(/\"/g, ""); $('#offer_deriviative').val(selected); } }); }); } });