Forums

Problem with selecred dropdown value in edit form with Chronoforms5

kiwiup 20 Feb, 2015
Hi,
I creaated a dropdown dynamically chained by following a FAQ published in this forum.
This is the Custom code in the ajax event about second dropdown element like the suggestions in the FAQ.

<?php
$options = array();
if ( !$form->data['Dataform'] || count($form->data['Dataform']) < 1 ) {
// no result was found
$options[] = 'Please select a category';
} else {
foreach ( $form->data['Dataform'] as $d ) {
$options[$d['id_pro']] = $d['nome_provincia'];
}
}
echo json_encode($options);
?>


In the edit form I would like, when open the form, to show in the dropdown a value chosen and saved previously.
I know that in the dropdown element there is a tag selected used to show the value.
Someone has an idea to solve it?
I have to put some code in the foreach cicle?

Thanks

Kiwiup
Max_admin 20 Feb, 2015
Hi Kiwiup,

You will need a different "edit" form (just copy your existing form), and you will need to use the "Dynamic data" section in the dropdown to load the dropdown with proper results using a "db read" action, there is a demo form about this feature!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin 20 Feb, 2015
Thinking about this again, you don't need a new form, just configure the 2nd dropdown for dynamic data and use "db read" in your form, if a record is found then a list of options will be loaded, if not then just don't trigger the "db read", for this switching you may use an "Event switcher" action.
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kiwiup 20 Feb, 2015
Hi Max.
thanks for your hints but I tried to figure out a solution and I didn't get it.
In my entri form (named exampledrop) for example one field is called dropdown2. I copied this form and renamed iin viewexampledrop and connected wirh CC5 called viewdrop (model id listexdrop). In the edit form (viewexampledrop) same field is called listexdrop['dropdwon2']. In this way if I change his value I can save it in the same table.
My problem, in the edit form, is how write a right code (custom code in ajax event) to show the value stored and the others value to select another if I made mistake in the first choice (entri from).
I followed your hints but I couldn't got anything.
Thanks a lot.

Kiwiup
kiwiup 20 Feb, 2015
Hi Max

Array
(
    [cont] => lists
    [ccname] => viewexdrop
    [act] => edit
    [gcb] => 163
    [listexdrop] => Array
        (
            [id] => 163
            [uniq_id] => e51055e6a9f8fd4de15b5af64f5bf837e99c0e6b
            [user_id] => 0
            [created] => 2015-02-19 08:54:47
            [modified] => 2015-02-20 14:39:14
            [dropdown1] => 9
            [dropdown2] => 45
            [dropdown5] => 3450
        )

    [listdrop1] => Array
        (
            [id_reg] => 9
            [nome_regione] => Lombardia
        )

    [listdrop2] => Array
        (
            [id_pro] => 45
            [id_reg] => 9
            [nome_provincia] => Mantova


In the first dorpdown I have a right name Lombardia but in the second dropdown I have Bergamo (first nalme list of the provicne of Lombardia) instead of Mantova that should be ['listexdrop']['dropdown2']

I would like to modify something in the ajax event code to load a value from table and to have the possibility to modify it.

Thanks
Max_admin 21 Feb, 2015
Answer
Hi Kiwiup,

For loading existing results, you don't need to use AJAX, just use a "db read" action and use the "dynamic data" section in the dropdown as explained in other topics.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kiwiup 21 Feb, 2015
Hi Max,
thanks for your hint.
I solved partially the problem. Now when I open a record in edit form the dropdown element show a right values. But I lost a ajax event (Custom code) that connect a dropdown each other. In other words in the entry form when I choose a value in the first dropdown the second dropdown shows only a few element connected by id with the first dropdown. For example
first drpdown: id_reg, region;
second dropdown: id_pro,id_reg,province
third dropdown: id_com,id_pro,id_reg,town

So if I choose id_reg = 2 from first dropdown in the second one I have only 5 element to choose and so on.
If in the edit form I set a dynamic data for the seocnd dropdown when I open a edit form to modify a value for example for the seocnd dropdown I have all the values (109) of province.
How can I have only few elements in the edit form by according to a value selected in the first dropdown like in the entry form?

Thanks a lot.
Max_admin 23 Feb, 2015
Hi Kiwiup,

Your "db read" must have the correct conditions in the "Conditions" box in order to load the results matching the value of the first dropdown only, the conditions depends on your table, it may match the conditions used in the "db read" in the AJAX event.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.