dependent on field

edited November 2016 in Bug Reports
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

  • edited 2:14PM
    The code is setup so that only displays a dependent field for new values and select fields when you try and edit (the else part of the if(!$values) condition).
  • edited 2:14PM
    I understand this but if the else part does not exist the values are not loaded in the dependent fields when you edit. If there is another way to do this please advice as i need values to be selected on edit as well
  • edited 2:14PM
    The dependent field should automatically set the value after the ajax options load. A few questions:
    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))?
  • edited November 2016
    answer to your questions:
    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
  • edited 2:14PM
    Are there any options coming back from the Ajax request that is getting fired when you change the value on the main select field (check the browser's console for the Network activity to see the Ajax request)?
  • edited 2:14PM
    yes there are when i change the main dropdown. But the other three dropdowns do not have anything in them when i first go in to edit the values. i would like the dropdowns to show the values already selected and be able to change those values without having to change the main value to get them to work. Please advice
  • edited 2:14PM
    Unfortunately, it's difficult for me to understand and test your issue out completely without knowing the full model and database scope. If you are able to provide the modules, models and SQL information necessary to replicate the issue in a fresh install of FUEL, I may be of more help.
  • edited December 2016
    I'm currently hacking the custom_fields.js file to try to load the fields when you click edit based on the first field once I figure it out I hopefully will load each Dropdown with the correct fields showing and each field having all of the values in the dropdown. If you could possibly help with this it would be apprciated.
  • edited 2:14PM
    ok i found a solution or a way round this i created a copy field which i attached a js file to this checks the values on ready and gets the missing dropdowns and selects the correct value $(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); } }); }); } });
Sign In or Register to comment.