Welcome, Guest
Username: Password: Remember me

TOPIC: listKey argument for ajax combo box

listKey argument for ajax combo box 01 Oct 2012 08:31 #4177

  • Ferm
  • Ferm's Avatar
  • Offline
  • Junior Member
  • Posts: 39
  • Thank you received: 6
  • Karma: 2
Really easy question this time: Am I right in thinking that a drop-down list in a grod created with JDom/Ajax does not take the listKey argument? So if I use

JDom::_('html.form.input.ajax', array(...

the array does not have an element 'listKey' => 'the_field_I_want_to_return'

I think the non-Ajax version of the call does and it would be great to have it for the Ajax function as well as it would allow you ot link tables on other fields than the id field without having to make an extra database call to retrive the value when you are building the query.

Grateful for any help!
The administrator has disabled public write access.

Re: listKey argument for ajax combo box 01 Oct 2012 08:56 #4178

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi Ferm,

All you need to do on the grid is drag the field from the related table. This is accessible by;
  1. expanding the foreign key (fk) node in your fields list
  2. selecting the field of your choice from the related table to display - it's name/title for instance.
You can make it linkable to a specific in-context view or to a delete or edit task on each item in the grid too, using a related field as the title attribute of the link.

Best,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: listKey argument for ajax combo box 01 Oct 2012 10:38 #4180

  • Ferm
  • Ferm's Avatar
  • Offline
  • Junior Member
  • Posts: 39
  • Thank you received: 6
  • Karma: 2
Hi Gez,

I am probably misunderstanding you, but I think you are referreng to the laout design where I can drag a specific field into a combo box. My question is this:

I have a table with, say, the status of something, the table will have two fields, status_codea and status_name. Status_code is something like 10, 20, 30 etc and status_name is the text describing it 'preliminary', 'confirmed' etc. What I would llike to do is os to show status_name in the drop down but to get the content of status_code returned instead of the id.

So if the first row in the table has code 10 and the text 'preliminary' I want the drop-down to return 10 when the user selct 'preliminary' and not 0 which is likely to be the id of that record.

I will then set this as a filter and display the list again but only showing records with the status_code 10.

Do you see what I am after?
The administrator has disabled public write access.

Re: listKey argument for ajax combo box 01 Oct 2012 10:55 #4181

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
OK, I understand what you mean... Not 100% on how you're implementing... Let me explain what I mean but first, a question or 4...
Ferm wrote:
...Status_code is something like 10, 20, 30...
What is the importance of status_code? What I mean is, are they actually going to be used in any numeric calculations ever? If not, just create records in status table *****ADD ***** I mean, why not just have a text field for the labelFerm wrote:
'preliminary', 'confirmed' etc.
then use the auto-generated id on the table...? ***** End ******

If they are important, you might want to look at enum field type and populate it with a predifined list of key->value pairs - presumably, these values/labels aren't going to change right - I mean, you're not going to add different types of status all the time? Sounds like the publishing system implemented in joomla.

Does this make sense?

Gez

P.S. Combobox only works on foreign keys so I assume that these status's will be applied to some records in another table like 'tasks' or something, right?
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 01 Oct 2012 11:19 by JoomGuy. Reason: ***** ADD ******
The administrator has disabled public write access.

Re: listKey argument for ajax combo box 01 Oct 2012 11:37 #4187

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi Ferm,

Not sure if you saw my last post yet but I'm not sure that I did understand on looking back at your post...

If I'm now correct in assuming that you want to create a toggleable field on a grid to change the status of items in a particular table, using the values you define in your status table, you might want to look t this function that can be found in the file 'administrator/classes/jtable.php' - YourcomponentnameTable Class that extends JTable...

In there exists a function for changing the state... You could copy/adapt this function to your needs
public function toggle($fieldName, $pk = null, $max = 1)
	{
		// If field do not exists return false
		if (!property_exists($this, $fieldName))
			return false;

		$this->load($pk);

		//Calculate the new value
		$value = $this->$fieldName + 1;
		if ($value > $max)
			$value = 0;


		// Check the row in by primary key.
		$query = $this->_db->getQuery(true);
		$query->update($this->_tbl);
		$query->set($this->_db->quoteName($fieldName) . ' = ' . (int)$value);
		$query->where($this->_tbl_key . ' = ' . $this->_db->quote($pk));
		$this->_db->setQuery($query);

		// Check for a database error.
		if (!$this->_db->query())
			return false;

		// Set table values in the object.
		$this->fieldName = $value;

		return true;
	}
Hope thi helps,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: listKey argument for ajax combo box 01 Oct 2012 12:52 #4195

  • Ferm
  • Ferm's Avatar
  • Offline
  • Junior Member
  • Posts: 39
  • Thank you received: 6
  • Karma: 2
Hi,

Thanks for trying to help!

I am probably not very good at explaning this. What I want to do is to have a filter where I can filter out rows in a table depending on the status of the record. So, for example, the user could click on the drop-down and selct 'completed' or something and the list would only include records with status 'completed'

One thing I am pretty sure about is that I don't know today exactly what statuses will be required in the future. Therefore, it is better to have a table witht the different statues instead of coding it into an enum.

It is not a major problem, but it would be better to be able to also include he status code in the table. The reason for this is that it is easier to have codes like 10, 20, 30 etc if you want to insert new records later on. So if 10 is 'preliminary' and 20 is 'completed', it is quite handy to be able to add the 'work in progress' status as 15. If you use the id of the table, 'preliminary' becomes 1, 'completed' 2 and 'work in progress' 3.

As mentioned in my previous post, it is possible to get the JDom method html.form.input.select to generate the code to do this by specifying the 'listKey' parameter and my question was if there is an equivalent paramter for the corresponding ajax method (html.form.input.ajax).

It is not a big deal, I can either just use the non-ajax method or I can just look up the status code when the filter is set and add it to the query.
The administrator has disabled public write access.

Re: listKey argument for ajax combo box 01 Oct 2012 13:24 #4198

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Right, I understand a bit better now...

So, really, having the status_code field is about being able to order the statuses in the combo, right - if you're not going to use it in any calcs? Coz at the end of the day, unless you're going to calculate something based on it, or you want to show some sort of shortened version of the text, it's actually of no consequence as long as the user knows what status he/she is wanting to filter on, and of course, having them in order of whatever workflow you're working to obviously.

In that case, even though you're only talking about 2 digits with your proposed status_code, I'd use an ordering field to reduce the data and adapt the query that gets the values in your model adding, "ORDER BY ordering" where ordering is the name of the field. There is another advantage here in that you can order them how you like with the ordering widget in the grid layout of your status table.

Does that seem like a way to go?


Sorry if I didn't answer quite what you were looking for...

Regards,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: listKey argument for ajax combo box 01 Oct 2012 13:33 #4199

  • Ferm
  • Ferm's Avatar
  • Offline
  • Junior Member
  • Posts: 39
  • Thank you received: 6
  • Karma: 2
You are absolutely right and adding the order by is a really good idea. I will do as you suggest. Thanks for your help!
The administrator has disabled public write access.

Re: listKey argument for ajax combo box 01 Oct 2012 13:36 #4200

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
No Probs!

G
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: listKey argument for ajax combo box 03 Oct 2012 13:13 #4237

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Well, I don't know if you still need to use this listKey argument, I answer to you.
The ajax JDom call is only a wrapper. It does nothing else than writing a container div and calling a HTTP query. The result will be shown in this div.
The response containing the combo is coming from the view file of the requested list. (view.html.php), in the displayAjax() function.
There, you can find another JDom call (warning, it is complex).
For instance, try to replace :
html.form.input.select, to :
html.form.input.radio

If something changed, it means that you found the right JDom call.
There you can change the listKey argument.

Hope it helps.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: listKey argument for ajax combo box 03 Oct 2012 19:50 #4254

  • Ferm
  • Ferm's Avatar
  • Offline
  • Junior Member
  • Posts: 39
  • Thank you received: 6
  • Karma: 2
To illustrate the question I created a new project called test project. It is really simple and has one table "cities" and one table "countries". The city table has a name field and a foreign key to the country table. The country table has two fields, country_code and name.

I created a simple grid for the cities table and included a combo box to allow you to filter the cities by country.

I then downloaded two versions of the component, one where the combo box has ajax loading and one where it hasn't. After installing both components in an empty joomla site, I amended the code in the template (default_filters.php) to include the 'listKey' => 'country_code' argument.

For both components, I populated the tables with Paris, Rome, Madrid and Berlin and France, Italy, Spain and Germany.

So in the non-ajax version, I have the following code:
<div class='filter filter_my_foreign_key'>

				<?php echo JDom::_('html.form.input.select', array(
						'dataKey' => 'filter_my_foreign_key',
						'dataValue' => $this->filters['my_foreign_key']->value,
						'list' => $this->filters['my_foreign_key']->list,
						'labelKey' => 'name',
						'nullLabel' => "TESTPROJECT_FILTER_NULL_MY_FOREIGN_KEY_NAME",
						'submitEventName' => 'onchange',
						'listKey' => 'country_code'
							
				));

				?>
			</div>

And for the component where the filter is ajax enabled, I have the following code:
<div class='filter filter_my_foreign_key'>

				<?php
				$filter = $this->filters['my_foreign_key'];
				echo JDom::_('html.form.input.ajax', array(
						'dataKey' => 'filter_my_foreign_key',
						'dataValue' => $filter->values[0],
						'ajaxContext' => 'testprojectajax.foreingkeytable.ajax.filter1',
						'ajaxVars' => array('values' => $filter->values),
						'listKey' =>'country_code'
				));
				?>
			</div>

The html generated in the non-ajax version is:
<div class="filter filter_my_foreign_key">
<select id="filter_my_foreign_key" class="inputbox " onchange="submitbutton();" name="filter_my_foreign_key">
<option value="">- My Foreign Key > Name -</option>
<option value="de">Germany</option>
<option value="es">Spain</option>
<option value="fr">France</option>
<option value="it">Italy</option>
</select>
</div>

And the ajax version generates this:
<div class="ajaxchain-filter ajaxchain-filter-hz">
<select id="__ajx_my_foreign_key" class="inputbox " onchange="jQuery("#filter_my_foreign_key").val(this.value);submitform();" name="__ajx_my_foreign_key">
<option selected="selected" value="">- Select my foreign key -</option>
<option value="2">Germany</option>
<option value="1">Spain</option>
<option value="4">France</option>
<option value="3">Italy</option>
</select>
</div>

So my question is whether the 'listKey' argument actually does anything for the ajax-generated code. As you can see, the values returned are the country.id value rather than the content of the country.country_code field. For the non-ajax code, the value returned will be the country code.

Do you see what i am after?
The administrator has disabled public write access.
Time to create page: 0.150 seconds

Get Started