I face the problem, that I have list formfield, where no values have been set in the xml formfield description. The values for the listfield will be created on runtime via jquery. When I choose a value, the value will be stored in the database, but with new open of the form the value from the database will be loaded, but not shown in the listfield. The listfield stays empty. Is this because of no standard values in the xml formfield description?
-
Yes that is exactly why it is not being set. You would have to pass the value to javascript and update the value in javascript as well.– David FritschCommented Feb 17, 2015 at 17:57
-
Ok, i've tried to integrate it as new variable derived from php. But in conjunction with Joomlas scriptdeclaration for integrating javascript, iam not able to get access to php variables. Therefor I made a seperate thread: joomla.stackexchange.com/questions/8675/…– PerinoCommented Feb 18, 2015 at 7:58
Add a comment
|
1 Answer
You should create a field element on the fly if the data for that element exists. For example:
if (isset($data->someField) && !empty($data->someField))
{
$element = new SimpleXMLElement(
'<field
name="someField"
type="text"
label="Label"
description="Description"
/>'
);
$form->setField($element);
}
You can place it in preprocessForm()
method or in getForm()
method of your model.
-
Thanks Dmitry for your input. To be more concret, I have two listfields which are in relations. The first listfield is responsible to offer different countries. The second listfield, which is in relation to the first listfield, should offer the states for the selected country of the first listfield. Which method would be best, to achieve that goal?– PerinoCommented Feb 18, 2015 at 9:16
-
Is there a reason you can't have all the data in the XML and use "showon" linked to the country select to show one of state/region listfields? So you'd have a separate listfield defined for every country that needs the second field, but only one would be shown. Commented Feb 18, 2015 at 9:40
-
@Dmitry: how do you handle changes of the select options in the listfield1 while the customer fills out the form? This question is also to Ville Niemi!– PerinoCommented Feb 18, 2015 at 14:02
-
-
I know JS functions while form element changes. But do you mean that I have to go with Ajax?– PerinoCommented Feb 22, 2015 at 7:07