Linking, chaining or binding jFormFieldLists together

116 views
Skip to first unread message

Riceman

unread,
Feb 3, 2012, 3:50:39 PM2/3/12
to joomla-de...@googlegroups.com
Hi All, 

I have three dropdown lists in an view having a jModelAdmin as the model. These dropdown lists all extends jFormFieldList.
The second list is dependent of the first list selected value and the last list is dependent of the second list's selected value. A drilldown kind of approach.

This is easy to do with javascript loading list options with ajax - javascript is the best way of going when creating a new record (id=0) 

But when you are in edit state the javascript approach is not that elegant. For that reason i am using php populate options and uses some where clauses to filter the dropdown lists but when the application is loaded the first time the list are not changeable. 

I like the dropdown lists to change there lists dynamically any ideas of how I can accomplish this? Here is a sample of second dropdown of how i populate the dropdown:

private function fetchList($table = '#__area', $field = null, $selectedCountry){
// Create a new query object
$db = JFactory::getDBO();
$query = $db->getQuery(true);
// Select some fields
$query->select("ID as value, {$field} as text
FROM
{$table}");
if(isset($selectedCountry)){
$query->where("(id_country = {$selectedCountry})");
}
$db->setQuery($query);
$areas = $db->loadAssocList();
return $areas;
}

method above is used by getOptions() to get $selectedCountry I use: $selectedCountry = $this->form->getValue('id_country');

Riceman

unread,
Feb 3, 2012, 3:52:01 PM2/3/12
to joomla-de...@googlegroups.com
Wow that was submitted fast - any ideas anyone ? 

Riceman : )

Mark Dexter

unread,
Feb 3, 2012, 7:43:36 PM2/3/12
to joomla-de...@googlegroups.com
If you have the values already (because you are editing an existing item), then you could use a plugin for the initial field loads. The event you want is onContentPrepareForm. This gives you access to the current form values so you can do what you need to do before the form is rendered.

As far as the Javascript method for relating two fields, it would be absolutely fantastic if we could figure out a way to make that generic, perhaps using a behavior to invoke it. I'm not sure the best way to do accomplish that. It would be cool for example to be able to somehow indicate in the XML file that the two fields are related. In your case, it looks like you are taking the value from one field and using it as the select in the query that populates the second field. I could see that being a generic case. In that example, we could create a JFormField type that grabs the value of a prior field for the query.

Anyway, maybe something to think about.

Mark

On Fri, Feb 3, 2012 at 12:52 PM, Riceman <thoma...@gmail.com> wrote:
Wow that was submitted fast - any ideas anyone ? 

Riceman : )

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/J-8XbuB1z7gJ.

To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Riceman

unread,
Feb 4, 2012, 8:05:31 AM2/4/12
to joomla-de...@googlegroups.com
Hi Mark, 

I am not into plugins, yet. I really think I have to look into plugins because it is here a lot of stuff happens - thanks didn't think about it at all.

The idea of linking two or more jForm elements together could really be a nice feature I hope You and your team will think about doing creating it.

For now I used a combination of jFormFieldList extending and javascript change events - It works fine but a little harder to test : ) However i will look into the matter when i get time in my schedule. If I create a generic way of linking jFormFields I will give you the code.

Riceman 

 
Reply all
Reply to author
Forward
0 new messages