AGRIGENTO,419084002 => ALESSANDRIADELLAROCCA,419084003 => ARAGONA,419084004 => BIVONA,419084005 => BURGIO,419084006 => CALAMONACI,etc....end withecho json_encode($comuni[$form->data["provincia"]]);Thant's works perfectly.The problem is that I need other 2 similar dropdown that basically use the same array, but for different field ID (provincia_ospite and provincia_documento)I cannot insert more on_load because the form doesn't save it ( event if I enlarge max_input_vars and suhosin.get.max_vars in php.ini)Anyone has a suggestion how to use the same array for different field IDs?Thanks"> 3 Dynamic dropdown with big array - Forums

Forums

3 Dynamic dropdown with big array

vismay 23 May, 2016
Hello,

I have this problem:

I need 3 different multiple dropdonws that according to one choice deliver a value from a big array.

Basically:

dropdown "provincia" call set dynamic option to custom code on_load_comuni

in custom code I have a huge array ( more than 500)
<?php
$comuni  = array(
	"AG" => array(419084001 => AGRIGENTO,
419084002 => ALESSANDRIADELLAROCCA,
419084003 => ARAGONA,
419084004 => BIVONA,
419084005 => BURGIO,
419084006 => CALAMONACI,
etc....

end with
echo json_encode($comuni[$form->data["provincia"]]);



Thant's works perfectly.

The problem is that I need other 2 similar dropdown that basically use the same array, but for different field ID (provincia_ospite and provincia_documento)

I cannot insert more on_load because the form doesn't save it ( event if I enlarge max_input_vars and suhosin.get.max_vars in php.ini)

Anyone has a suggestion how to use the same array for different field IDs?

Thanks
GreyHead 23 May, 2016
Hi vismay,

No user is going t thank you for a drop-down with 500 entries to scroll through. Have you thought of using an AutoCompleter?

You could include the option list from a separate file, and add it to the $form->data array - that way it would be available for all three drop-downs.

Bob
vismay 23 May, 2016
Yes, is an autocomplete! Or better, according to the choice of state, you will see a dropdown with 20 country.

Your suggestion looks OK, but how I can manage to connect a separate file to a data array?

Thanks
vismay 23 May, 2016
Ok, I've made it with:

require('comuni.php');
include('comuni.php');



Now I have another problem:

I use it with a multiplier to collect informations about different guests, but now the following dynamic dropdown take the array of the first one!

Any suggestion?

Thanks
GreyHead 23 May, 2016
Hi vismay,

I've never tried to put a double-drop-down inside a multiplier. Because the multiplier works by copying the first 'row' it probably can’t tell which drop-down the code should update. You may be able to do this by checking the ids of the drop-downs but I suspect that it still may not work.

How many people do you allow to be added? It might work if you create all of them in the form Designer tab and then hilde all but one.

Or it might be possible using Custom JavaScript to add the dynamic dropdown code when a new multiplier row is added.

Bob
vismay 27 May, 2016
Hi Bob,

I'm nearly finished with autocomplete but I have one problem.

I have a dropdown with select a value ( field ID dropdown);
a text field with autocomplete;

in setup I have an autocomplete processor that lead to on list_example.

In list example I have a custom code:

<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "
SELECT descrizione 
FROM tab_comuni 
WHERE provincia ='{$form->data['dropdown']}';
";
$db->setQuery($query);
$record_title = $db->loadColumn();

foreach($record_title as $title){
 if(!empty($form->data['tag']) AND stripos($title, $form->data['tag']) === false){ // title is Field name in autocompletter
  continue;
 }
 $json[] = array('id' => $title, 'text' => $title);
}
echo json_encode($json);
?>


{$form->data['dropdown']} doesn't work, but if I write a real value it works perfectly.

Is syntax correct?

Thanks
GreyHead 29 May, 2016
Hi vismay,

It looks OK if the value being passed back in the AJAX request is called dropdown - I'd suggest that you use your browser web developer tools to see what is being passed exactly. You can also use debug code there to echo out values for testing for example echo $query; - they will probably cause errors but you can see exactly what is happening.

Bob
vismay 30 May, 2016
The value passed is NULL.

It's possible that the value is not yet passed, because the autocomplete and relative ajax event is called before the assignment of the dropdown.

The form is like this:

dropdown ( value)

autocomplete ( according to value choose the table_field)

It's possible to load it dynamically, so the autocomplete read it in realtime?
GreyHead 30 May, 2016
Hi vismay,

I'm sorry, I don't understand the question. I can’t work out what is happening when.

Is this all when the form loads? Or after the user changes something?

The answer is probably that you will need custom JavaScript to make this work.

Bob
vismay 30 May, 2016
Sorry... ;-)

thi sis the form:

I have a DB table with: region | city | doce

Then a form with:

dropdown ( that choose the region )

then an autocomplete ( according to the choice of region, shows only the cities of that region)
-----------

the autocomplete processor is in onload, that calls an event

<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "
SELECT city 
FROM tab_comuni 
WHERE region ='{$form->data['dropdown']}';
";
$db->setQuery($query);
$record_title = $db->loadColumn();

foreach($record_title as $title){
 if(!empty($form->data['tag']) AND stripos($title, $form->data['tag']) === false){ // title is Field name in autocompletter
  continue;
 }
 $json[] = array('id' => $title, 'text' => $title);
}
echo json_encode($json);


Looks like the autocomplete doesn't receive the value choosen in dropdown.

I need to make it available for the autocomplete.

Hope is clear
GreyHead 25 Jun, 2016
Hi vismay,

The code looks OK assuming that the $form->data[''] names are correct. if you use your browser web-developer tools then you should be able to see what data is being returned (in Chrome it's on the Network tab). That will let you debug the event code. For example you can add echo $query; to see what query is being created and test that in PHPMyAdmin.

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