Form field with dropdownlist and bound javascript function

edited May 2016 in Feature Requests
Hi,
I have a question about something I am not pretty sure how to implement in the fuel CMS.
In my old application (only working based on CI) I got a form where I have a dropdown list with template values.
So if one of these template values is selected by the user other form fields are being filled with template based values.

I realized this with binding a JSON call to each of the dropdown values:

[...] $templ_options = array(); $templ_attr = "class = 'input_dropdown' id = 'input_dropdown'"; $templ_options[0] = 'Vorlage wählen...'; foreach($templates as $templ) { $templ_options[$templ['template_id']] = $templ['template_name']; } ?> <script type="text/javascript"> $(function() { $('#input_dropdown').bind('change', function(e) { $.getJSON('<?=base_url('einsatz/einsatz_admin/json_get_einsatz_template')?>/' + $('#input_dropdown').val(), function(data) { $.each(data, function(i,item) { if (item.field == "einsatzname") { $('#einsatzname').val(item.value); } else if (item.field == "einsatzlage") { $('#einsatzlage').val(item.value); } else if (item.field == "einsatzart") { var arten = item.value.split('|'); $.each(arten, function(index, value) { $('#t_' + value).attr('checked', true); }); } else if (item.field == "einsatzfahrzeug") { var fahrzeuge = item.value.split('|'); $.each(fahrzeuge, function(index, value) { $('#f_' + value).attr('checked', true); }); } }); } ); }); }); </script> [...] <tr> <td colspan='2'><?=form_dropdown('einsatz_template', $templ_options, 0, $templ_attr)?></td> </tr>

What would be the best way to achieve this in fuel CMS?

Comments

Sign In or Register to comment.