Forms in J1.5 Extension: How to add a conditional list

Locked
krautela
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Mon Sep 25, 2006 1:14 pm

Forms in J1.5 Extension: How to add a conditional list

Post by krautela » Fri Jun 20, 2008 9:29 am

I am new to Joomla extension coding and have floated a few questions here already. I am starting a new topic as question is bit different from others.

1.I have a form which prompts user to select "state's Name" and "district's Name". I want district's name list to appear after selection of state's name from the list. This is kinda conditional requirement. I have tried to find answers on some of the javascript forums but not much luck. can anyone help?

2. Also related to above problem there is a small issue. I have state names and district names in a separate database tables. i use JHTML's select generic list tool to create the list for the forms. Now I am struggling with the issue as to how to make a selection of all states ( this is for query) and also select none as a value when doing records editing ( where state or district name appears). This is complicated as i am using the ID instead of name strings.

one possible way to solve the problem was if i added two entities "all" and "none" as well, but i think it is not very elegant and dynamic solution in my opinion.

secteur
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 146
Joined: Tue Nov 08, 2005 9:32 am
Location: Malaysia

Re: Forms in J1.5 Extension: How to add a conditional list

Post by secteur » Mon Jul 07, 2008 5:04 pm

Hi,
regarding point 1, you might be interested in what I posted here: http://forum.joomla.org/viewtopic.php?f=304&t=257522
Sounds like the same kind of thing, only with states and districts (instead of countries and states)

As for point 2, I dont really understand what you mean... Do you wish to have one more option in your select which would be "Select none"?
In that case, you can use

Code: Select all

$states[] = JHTML::_( 'select.option', 0, JText::_( 'SELECT NONE' ) );
// Then get your list
$query = ' SELECT id AS value, name AS text FROM #__states';
// Assuming that you are in the model
$states = array_merge( $states, $this->getList( $query ) );
// Build the list with the attributes you need; assuming that $data is what you loaded from the DB
$listStates = JHTML::_( 'select.genericlist', $states, 'states', null, 'value', 'text', $data->state );
If you want your Select none to be at the end, change one line

Code: Select all

$states = array_merge( $this->getList( $query ), $states );

Not sure that this is what you needed, but I hope it helps.

krautela
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Mon Sep 25, 2006 1:14 pm

Re: Forms in J1.5 Extension: How to add a conditional list

Post by krautela » Wed Jul 09, 2008 6:49 pm

thanks secteur!!

i will try this solution and get back.
i ahve one more problem for frontend pagination in extension.
this is the link for the thread where i have posted it. if you know of a solution, please help

http://forum.joomla.org/viewtopic.php?f ... 9#p1345599


Locked

Return to “Joombie Tools of the Trade”