Hello,
I have two dropdowns which are getting the data from two separate tables from the database. That works so fine. But how can I put them in relationship? I want that the second dropdown only show the corresponding values to the first dropdown:
e.g.
If I select BMW, I only want to show 3er, 5er in the second dropdown.
Is this possible?
Thanks, Alex
I have two dropdowns which are getting the data from two separate tables from the database. That works so fine. But how can I put them in relationship? I want that the second dropdown only show the corresponding values to the first dropdown:
e.g.
ID;Marke
1;BMW
2;Audi
ID;Marke;Modell
1;1;3er
2;1;5er
3;2;A4
4;2;A6
If I select BMW, I only want to show 3er, 5er in the second dropdown.
Is this possible?
Thanks, Alex
Hello Bob,
thanks for the link.
Ajax actions works but I don't get the value from field 1 (fMarke) to field 2 (fModell). The script throws: Notice: Undefined index: fMarke
If I check fMarke, it is not in the array. If I delete condition in fModell, both dropdowns have the values from the database, so drowpdowns a filled without errors.
data connection for fModell / fields: Marke, Modell
custom code in designer:
You can see it here:
http://autobarankauf.berlin/
Thanks, Alex
thanks for the link.
Ajax actions works but I don't get the value from field 1 (fMarke) to field 2 (fModell). The script throws: Notice: Undefined index: fMarke
If I check fMarke, it is not in the array. If I delete condition in fModell, both dropdowns have the values from the database, so drowpdowns a filled without errors.
data connection for fModell / fields: Marke, Modell
<?php
return array( 'Modell' => $form->data['fMarke'] );
?>
custom code in designer:
<?php
$options = array();
if ( !$form->data['fMarke'] || count($form->data['fMarke']) < 1 ) {
// no result was found
$options[] = 'Please select a category';
} else {
foreach ( $form->data['fMarke'] as $d ) {
$options[$d['id']] = $d['title'];
}
}
echo json_encode($options);
?>
You can see it here:
http://autobarankauf.berlin/
Thanks, Alex
Hi Alex,
It looks as though you have put that PHP in the DB Read Conditions box - it needs to go into a Custom Code action after the DB Read action.
Bob
It looks as though you have put that PHP in the DB Read Conditions box - it needs to go into a Custom Code action after the DB Read action.
Bob
<?php
return array( 'Modell' => $form->data['fMarke'] );
?>
only this code is on condition.
Hi Alex,
I can't work out how you have this set up. Those Notices should only apply when the Ajax event is called. They are there because when it is called there is no Marke set.
There is also a problem that Marke doesn't have a null option like 'Please choose' with no value.
It also looks as though you may have set the event to look for a value of '' - that's not the same as empty, it's a string with two quotes.
Bob
I can't work out how you have this set up. Those Notices should only apply when the Ajax event is called. They are there because when it is called there is no Marke set.
There is also a problem that Marke doesn't have a null option like 'Please choose' with no value.
It also looks as though you may have set the event to look for a value of '' - that's not the same as empty, it's a string with two quotes.
Bob
Hello Bob,
I am a little bit confused. The notices, which were irritating, were shown because of the unhandled isset.
So far so good.
I tried to reduce failure, so I kicked all out, what I don't need at first.
In the second dropdown I now insert only a fix condition,
In the DB there are 9 entries for
but the dropdown only shows 1 (multiselect is enabled). If there is no condition all entries are displayed correct.
If I change value on dropdown 1 (fModell), dropdown 2 clears all entries.
In the console is following error after ajax-event:
Alex
I am a little bit confused. The notices, which were irritating, were shown because of the unhandled isset.
So far so good.
I tried to reduce failure, so I kicked all out, what I don't need at first.
In the second dropdown I now insert only a fix condition,
<?php
return array( 'Marke' => 1);
?>
In the DB there are 9 entries for
SELECT * FROM `kfz_Modell` WHERE Marke=1
but the dropdown only shows 1 (multiselect is enabled). If there is no condition all entries are displayed correct.
If I change value on dropdown 1 (fModell), dropdown 2 clears all entries.
In the console is following error after ajax-event:
SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
Alex
Hi Alex,
If I look at the form the Ajax call URL is
Bob
If I look at the form the Ajax call URL is
http://autobarankauf.berlin/index.php?chronoform=Fahrzeuge&event=ajax&tvout=ajax&fMarke=10
it is missing the option=com_chronoforms5& part
Bob
Hi Alex,
It looks as though it is being set as an SEF URL on your site. Does it work from the View Form link in the Forms Manager?
I suggest that you try setting Relative URL to No in the form HTML (Render Form) action and see if that fixes the problem.
Bob
It looks as though it is being set as an SEF URL on your site. Does it work from the View Form link in the Forms Manager?
I suggest that you try setting Relative URL to No in the form HTML (Render Form) action and see if that fixes the problem.
Bob
Hi Alex,
By all means send me the Admin login, but I'm travelling this weekend so probably won't look at it until after I get home late on Monday.
Bob
By all means send me the Admin login, but I'm travelling this weekend so probably won't look at it until after I get home late on Monday.
Bob
Hi Alex,
Not yet - I can't see how the Ajax URL is being set. I've asked Max to take a look at it,
Bob
Not yet - I can't see how the Ajax URL is being set. I've asked Max to take a look at it,
Bob
I have just checked this, the form works as expected but it doesn't have an event named "ajax" to actually process the dropdown request and return the results, please check the demo-dynamic-dropdown form for how to set this up!
Regards,
Max
Regards,
Max
Hi Alex,
Please see Max's reply before this. I've added the missing ajax event to your form and it is now working. There is more info in this FAQ.
Bob
Please see Max's reply before this. I've added the missing ajax event to your form and it is now working. There is more info in this FAQ.
Bob
Many many thanks!😀 😀 😀 I see what you mean. I have read the article more than once, but misunderstood this paragraph. 😲
Why does my second dropdown only shows one value (multiselect enabled) on startup? There should be more than one. In the ajax-event all values are correct?
Why does my second dropdown only shows one value (multiselect enabled) on startup? There should be more than one. In the ajax-event all values are correct?
From where the select data come at startup ?
If you are using a "handle arrays" action to save a multi value element, then the values will be concatenated using commas, so you need to separate them again when the results are loaded.
This topic is locked and no more replies can be posted.