Forums

dbread conditions iterations

jhaviro 26 Apr, 2017
How are you.

I need a little help to build a special condition in a dbread.
The condition must be based on 2 dropdown fields and the result shows it in a third dropdown ..

The first field (dropdown) is simple selection.
The second field (dropdown) is multi-select.

Dropdown27 (single selection): example:
Option1 1 = Spain
Option2 2 = usa
etc..

idioma_destino [] (multi-select): example:
Option1 a = A1 selected
Option2 b = A2 selected
Option2 c = A3

I need a condition with iteration for Dropdown2.
Return array condition: Dropdown1, Dropdown2[]

Currently this is the real code:

<? Php
Return array ('cd_language' => $ form-> data ['dropdown27'], 'cd_servicio' => $ form-> data ['idioma_destino']);
?>

It works, but I can only read (with ajax) the last selected item from dropdown2
How do I make a loop for the multiselect dropdown?

Pseudo code:
Return array ('cd_language_name' => $ form-> data ['dropdown27'], 'cd_servicio' => $ form-> data ['idioma_destino'] [0]);
Return array ('cd_language_name' => $ form-> data ['dropdown27'], 'cd_servicio' => $ form-> data ['idioma_destino'] [1]);
Return array ('cd_language') => $ form-> data ['dropdown27'], 'cd_servicio' => $ form-> data ['idioma_destino'] [2]);

I just need the AJAX construct works fine ... I need the iteration with the second dropdown multi select.

thank you very much
a greeting!
Javierp
Max_admin 26 Apr, 2017
Hi Javierp,

If your second dropdown is a multi select then it should send an array of values automatically, your dropdown field name has a [] at the end ?

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jhaviro 27 Apr, 2017
Hello again.

Yes, the second dropdown field has [] at the end.
This is my conditions but only get last data.
the field multiselect name is: idioma_destino[]

<? php
return array ('cd_language' => $ form-> data ['dropdown27'], 'cd_servicio' => $ form-> data ['idioma_destino']);
?>
Max_admin 27 Apr, 2017
Hi Javier,

Did you check the debug results ? what is the SQL query generated ?

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jhaviro 28 Apr, 2017
Goodnight

I find it very difficult to explain the operation in English, sorry.
I have tried placing a debugger action on an ajax event but it does not work.

I attach the form and the table from which I extract the data
If you want to see it working:
link to form test


Muchas gracias
javierp.
GreyHead 28 Apr, 2017
Hi Javier,

You can't see the results of a Debugger action in an Ajax event directly in the browser but you can use your browser web developer tools to see what is being returned - and that can include the debugger output. I use Chrome and in the developer tools > Network tab I can see the data being returned from your dropdown - for example
{"132":"Catal\u00e1n","7":"Espa\u00f1ol","139":"Franc\u00e9s","43":"Ingl\u00e9s","137":"Italiano","150":"Portugu\u00e9s","131":"Serbio\/Croata"}


There is a JavaScript error on the page though I'm not sure if that is causing the problem.

Bob
jhaviro 28 Apr, 2017
Hello!
Oh yeah. In the browser debugger always retrieve the data of the last element of the dropdown: If I have selected in the first dropdown: "Spanish" and in the second multiple dropdown "Arabe" and "Belarusian" the condition only works with the last element of the array " Spanish "and" Belarusian ".... I explain better: if I select" Spain "and" Arabic "the result is correct. Then I add the second dropdown" Belarusian "and delete the previous one, and place the new one, always the last one.
The javascript error is for ".lenght" badly used. The API is not mine. I do not think it influences this, however, I'll try it, I'm looking for another similar API.

TYVM!
javierp.
jhaviro 30 Apr, 2017
2 Likes
Hello Goodnight.

I think I've found the problem. When I read the data in the table, there are entries with equal value, eg(no real):
Dropdown multiple:
Option 1 value 74 text 0.20
Option 2 value 74 text 0.20
Option 3 value 74 text 0.20

When the result was equal values and texts, it only leaves ONE option. I'm not sure why this happens, but I've fixed it by reading the ID (unique) + text, eg (no real):
Dropdown multiple:
Option 1 value 1 (id) text 0,20
Option 2 value 2 (id) text 0.20
Option 3 value 3 (id) text 0.20

Here form fixed

I want to thank you for all your cooperation.
Sincerely
Javierp.
This topic is locked and no more replies can be posted.