Friday 27 December 2013

Joomla Administration; How to add a custom dropdown list to a form

The aim here was to make some customisations to the Messaging component.  I wanted to change the user dropdown to only select from our shoppers.


Here's how I fixed this.

I added this file administrator/com_message/models/fields/ourshoppers.php

getQuery(true);
 
                $query->select('user_id As value, username As text');
                $query->from('#__users AS a');   
    $query->join('LEFT', '#__mijoshop_user AS m ON m.userid = a.id');
                $query->order('a.username');
                $query->where('m.status = 1');
 
                // Get the options.
                $db->setQuery($query);
 
                $options = $db->loadObjectList();
 
                // Check for a database error.
                if ($db->getErrorNum()) {
                        JError::raiseWarning(500, $db->getErrorMsg());
                }
 
                return $options;
        }
}


defined('JPATH_BASE') or die;

jimport('joomla.html.html');
jimport('joomla.form.formfield');
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');

/**
 * Custom Field class for the Joomla Framework.
 *
 * @package             Joomla.Administrator
 * @subpackage          com_my
 * @since               1.6
 */
class JFormFieldOurShoppers extends JFormFieldList
{
        /**
         * The form field type.
         *
         * @var         string
         * @since       1.6
         */
        protected $type = 'OurShoppers';

        /**
         * Method to get the field options.
         *
         * @return      array   The field option objects.
         * @since       1.6
         */
        public function getOptions()
        {
                // Initialize variables.
                $options = array();

                $db     = JFactory::getDbo();
                $query  = $db->getQuery(true);

                $query->select('user_id As value, username As text');
                $query->from('#__users AS a');  
                $query->join('LEFT', '#__mijoshop_user AS m ON m.userid = a.id');
                $query->order('a.username');
                $query->where('m.status = 1');

                // Get the options.
                $db->setQuery($query);

                $options = $db->loadObjectList();

                // Check for a database error.
                if ($db->getErrorNum()) {
                        JError::raiseWarning(500, $db->getErrorMsg());
                }

                return $options;
        }
}




and then in administrator/com_messages/models/forms/message.xml
FIND
name="user_id_to"



And underneath change the type to 'our shoppers'

type="OurShoppers"

type="OurShoppers"






###########################

Here's what I searched for on Google


joomla com_messages model how to effect the recipient dropdown

joomla messages components how to effect the recipient dropdown

joomla changing a input-append in administrator


how to make your own customised forms .  Heres a great article.

http://docs.joomla.org/J2.5:How_to_add_custom_filters_to_components


index.php?

option=com_users&view=users&layout=modal&tmpl=component&field=jform_us

er_id_to&groups=WyI3IiwiOCJd&excluded=WyI4MjIiXQ==

joomla 3 administrator models/fields custom dropdown


I NEED TO LINK UP TO MIJOSHOP CUSTOMER AND NOT MIJOSHOP USER.  !! match on email !!


Here's the answer on this page ->

http://docs.joomla.org/Creating_a_custom_form_field_type

No comments: