1

i got the following field in my form.xml-definition:

<field  name="attachedto" 
        type="sql"  
        label="COM_BESTIA_FIELD_ATTACHEDTO" 
        query="SELECT id, title FROM #__bestia_items WHERE state = 1" 
        key_field="id" 
        value_field="title" 
        multiple="true"
        required="false">
</field>    

Now I would like to change the state = 1 according to the settings in the configuration of the component. If config says "use state = 0" the query should change from WHERE state = 1 to WHERE state = 0.

How can I do that?

1 Answer 1

3

With the SQL form field type which you are using this is not possible. However you could develop a custom form field type.. Consider subclassing the existing JFormFieldList which will help you a lot. You will only have to write the getOptions() method.

<?php
defined('_JEXEC') or die('Restricted access');

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

class JFormFieldAttachedto extends JFormFieldList {

    protected $type = 'Attachedto';

    public function getOptions() 
    {
        // Get component config (JComponentHelper::getParams('com_yourcomponent'));
        // Make SQL query
        // Return all options as array
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.