× Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues

Show List of Items from Component in Module Select

6 năm 7 tháng trước - 6 năm 7 tháng trước #1780 bởi Matthew Jones
I have a component where the user can enter a list of locations. In the module, I want them to be able to select a single location in the "item" tab. Currently there is a text field there requesting the item's ID. I want to replace that with a dropdown list of ll the items (locations) that were entered in the component.

Can someone point me in the right direction of how to do this?

Here's what I have so far:

/com_name/administrator/models/fields/SingleLocation.php
<?php

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

JFormHelper::loadFieldClass('list');

class JFormFieldSingleLocation extends JFormFieldList {
  /**
	 * The field type.
	 *
	 * @var         string
	 */
	protected $type = 'SingleLocation';

  /**
	 * Method to get a list of options for a list input.
	 *
	 * @return  array  An array of JHtml options.
	 */
	protected function getOptions()
	{
		$db    = JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->select('id,locationname');
		$query->from('#__name_location');
		$db->setQuery((string) $query);
		$locations = $db->loadObjectList();
		$options  = array();

		if ($locations)
		{
			foreach ($locations as $location)
			{
				$options[] = JHtml::_('select.option', $location->id, $location->locationname);
			}
		}

		$options = array_merge(parent::getOptions(), $options);

		return $options;
	}
}

I then added the following to /com_name/modules/mod_name/mod_name.xml
<fieldset
                name="item_content"
                label="MOD_NAME_ITEM_CONTENT_TAB"
                description="MOD_NAME_ITEM_CONTENT_TAB_DESC"
                addfieldpath="/administrator/components/com_name/administrator/models/fields">
                <field
                    name="item_table" type="list"
                    label="MOD_NAME_TABLE_LBL"
                    description="MOD_NAME_TABLE_DESC">

	                  <option value="#__name_location">#__name_location</option>
                </field>

                <field name="item_id" type="SingleLocation" label="Location"
	                 description="Location you want to display"
	                  required="true" />

All I get when I look at the module though is a textbox instead of a dropdown.

- Matthew
Last edit: 6 năm 7 tháng trước by Matthew Jones.

Vui lòng Đăng nhập hoặc Tạo tài khoản để tham gia cuộc hội thoại.

6 năm 7 tháng trước #1782 bởi Matthew Jones
Replied by Matthew Jones on topic Show List of Items from Component in Module Select
Figured it out. I needed to name the file singlelocation.php instead of SingleLocation.php.

Vui lòng Đăng nhập hoặc Tạo tài khoản để tham gia cuộc hội thoại.

Thời gian tải trang: 0.050 giây
Powered by Kunena Forum

We use cookies so that you can place orders and we can provide a better service. You can control the use of cookies at the individual browser level. If you reject cookies, you may still use our website, but your ability to use some features or areas of our website may be limited.