Forums

drop down and checkbox

admin_wiky 14 Apr, 2015
Hi all,

I am preparing the new form and I want to use dropdowns and checkboxes and I have some questions.
[list]May I use enum data type in DB for save from checkboxes? it saves as an array and it throws an error.
1054 Unknown column 'Array'

what data type Should I have in DB?[/list]
[list]May I combine dynamic dropdown with checkboxes? how?[/list]
GreyHead 14 Apr, 2015
Hi Homeopat,

I've never tried using the enum data type. Usually for multiple valued checkboxes use a Handle Arrays action to convert the values to a comma separated string and save the string in a column of Type VARCHAR()

Bob
admin_wiky 15 Apr, 2015
Hi Bob,

Calculus00s links helped me - I did it and it works.
Now I need to deal with the second part of my question.
I need to decide by selecting an option from a dropdown menu which Checkboxes will be displayed.
I peered into the FAQ and I know that I need to create multiple groups of checkboxes, but I do not know how to show one group of checkboxes based on the selected option from the dropdown menu.

thx
GreyHead 15 Apr, 2015
Hi homeopat.

What exactly needs to change. Is is a single set of checkboxes and you select different sub-sets? Or is it that you need to display a completely different checkbox group for each option?

Bob
admin_wiky 15 Apr, 2015
yes,

If I select option 1 then I need show checkboxes 1,2,3
If I select option 2 then I need show checkboxes 4,5,6
and so on

so I'll have to create many groups of checkboxes as options in the dropdown menu?
but then I have to modify php code of converting array to comma separated string.

could u pls help me?
Max_admin 15 Apr, 2015
Your checkboxes groups can be inside a container of type "div" each, then you can use the "Events" section in your dropdown to hide/show the container you want.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 16 Apr, 2015
I resume what I did.
in designer
i use model_id=him
I have dropdown menu with name=him[druh] and id=dropdown3. there I have defined events tab
[attachment=0]ScreenShot799.jpg[/attachment]
I have one group of checkboxes with name=him[vlastnost][] and id=checkbox_group5
in setup
all data are loaded dynamically from only one DB table correctly over 2 DB reads.
1 DB read loads data for dropdown menu with model id=druhy
1 DB read loads data for checkboxes with model id=vlastnosti.
I put custom code between DB reads and HTML (Render Form):

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


what I did wrong?
admin_wiky 16 Apr, 2015
I made some tries and found out that it works but not in time.
If I open new empty form and choose option on Druh HIM field then nothing is shown in Vlastnost HIM field.
[attachment=0]ScreenShot800.jpg[/attachment]
but If I open existing record, then the option in Vlastnost HIM field is shown
[attachment=1]ScreenShot801.jpg[/attachment]
it looks like the ajax isnt working or where is problem?
thx
GreyHead 16 Apr, 2015
Hi homeopat,

Please post a link to the form so I can take a quick look. It's hard to work out what is happening from the images here.

I did notice that you have used '' for empty options, I had some problems with this and found that leaving the box empty seemed to work better.

Bob
Max_admin 17 Apr, 2015
Hi homeopat,

Just leave the "value" box in the event totally empty if you want to trigger the event on empty value, don't use quotes at all since the empty value is actually an empty string.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 20 Apr, 2015
Hi Max,
I did it and nothing happened. When I choose an option in dropdown memu (druh him) then no option is not shown in row checkbox (Vlastnost him).
It looks like that ajax doesnt work.
Max_admin 21 Apr, 2015
Then most probably the event setup is incorrect, please post the current events you have!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 21 Apr, 2015
I have 2 events:
on load
[list=]2 db reads for dropdown (path:druhy) and for checkboxes (path:vlastnosti)[/list]
[list=]custom code[/list]

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

[list=3]html renderer[/list]
on submit
[list=1]custom code[/list]

// converts array to string
  $vlastnost_array = array
  (
    '1 osoba' => '1 osoba',
'2 osoby' => '2 osoby',
'2m' => '2m',
'3 osoby' => '3 osoby',
'3m' => '3m',
'4 kanálový' => '4 kanálový',
'8 kanálový' => '8 kanálový',
'all-in-one' => 'all-in-one',
'barová' => 'barová',
'DVR' => 'DVR',
'elektronický' => 'elektronický',
'klasická' => 'klasická',
'klasický' => 'klasický',
'křížový' => 'křížový',
'mechanický' => 'mechanický',
'nízké' => 'nízké',
'plochý' => 'plochý',
'pronájem' => 'pronájem',
'průmyslový' => 'průmyslový',
'přenosný' => 'přenosný',
'skládací' => 'skládací',
'stojan' => 'stojan',
'vlastni' => 'vlastni',
'vysoké' => 'vysoké'
  );
  $vlastnost = array();
  foreach ( $form->data[him]['vlastnost'] as $v ) 
  {
    $vlastnost[] = $vlastnost_array[$v];
  }
  $form->data[him]['vlastnost'] = implode(', ', $vlastnost);
?>

[list=2]Connection Action[/list]
Max_admin 28 Apr, 2015
Then, what do you do with the variable
$options
after you set it ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 28 Apr, 2015
Hi MaX,
I am not sure what do u mean? I just followed this faq how-do-i-build-a-dynamic-drop-down-in-cfv5

I modified previous settings.. Deleted db read and custom code from on load action and move them to on ajax action. but still not working. I combine dropdonw with checkbox group.

thx
admin_wiky 15 May, 2015
Hi Max,
could u please help me with this?

thx
GreyHead 23 May, 2015
Hi homeopat,

Looking at the form with the link you posted I can see that you still have '' in the event selectors, that is probably breaking the JavaScript there. In the form backup I can still see that in the vlasnost checkbox group.

I can't work out what your Ajax code is doing. It appears to be taking the values in vlastnost and turning them into an options list for vlastnost. Does it change anything?

I also can't work out what the Custom Code in the On Submit event is doing - it appears to be processing the $form->data[him]['vlastnost'] array but as far as I can see it doesn't actually change anything.

Bob
admin_wiky 09 Jun, 2015
Hi Bob,

I must say that I am lost with this problem. I just followed this FAQ. I resume what I did.
First in designer
  • put dropdown menu with id=drobdown3 and set some options to choose and set events
    [attachment=0]ScreenShot818.jpg[/attachment]

  • put checkbox group with id=checkbox_group5 fill in all possible options in options field (faq doesnt say how set up second dropdown although I use checkbox group). I have try use dynamic data with path vlastnosti, but it didnt help.


  • Second in setup tab
  • created event with name ajax

  • put db read with model: vlastnosti; fields: empty and conditions:
    <?php return array('druh' => $form->data['dropdown3']);?>

  • put custom code:
    <?php
    $options = array();
    if (!$form->data['vlastnosti'] || count($form->data['vlastnosti']) < 1 )
    {
      // no result was found
      $options[] = 'Please select a category';
    } 
    else
    {
      foreach ($form->data['vlastnosti'] as $d) 
      {
        $options[$d['vlastnost']] = $d['vlastnost'];
      }
    }
    echo json_encode($options);
    ?>

  • checkbox group doesnt show some options depending on the selected option in dropdown menu after this settings.
    I am not sure what I am doing wrong or if I forget something or If ajax doesnt work correctly.

    thank you.
    Max_admin 20 Jun, 2015
    I think "set options" and "set dynamic options" will only work for dropdowns, they can't build a checkboxes group!
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    admin_wiky 22 Jun, 2015
    Hi Max,
    But it works, but not immediately, correct ckeckboxes are shown (dependent on selected option in dropdown) after saving and open the record .... looks like a problem with ajax ... I am not sure if u understand me ...
    Max_admin 26 Jun, 2015
    I understand, the AJAX is not made to create a list of checkboxes, only to publish a dropdown options!
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    admin_wiky 06 Aug, 2015
    OK, I thought that.
    but could u help me with this problem?
    I need to show group of checkbox depending on choosing of dropdown.
    1 option in dropdown can have more than 1 option in checkbox group.
    GreyHead 06 Aug, 2015
    Hi homeopat,

    As Max said, the built-in event code won't handle that - it has to be done with custom JavaScript.

    Bob
    This topic is locked and no more replies can be posted.