Note that there are some explanatory texts on larger screens.

plurals
  1. POJoomla 1.7 multiple SQL list is not preselected on edit
    primarykey
    data
    text
    <p>In my joomla custom component I used the SQL field type (item.xml):</p> <pre><code> &lt;field name="colors" type="sql" query="SELECT id ,name FROM #__products_colors" multiple="multiple" key_field="id" value_field="name" class="inputbox" label="colors" description="COM_PRODUCTS_FORM_DESC_ITEM_COLORS" /&gt; </code></pre> <p>In my view I call the field like this:</p> <pre><code>&lt;?php echo $this-&gt;form-&gt;getInput('colors'); ?&gt; </code></pre> <p>Which gives me a nice and smooth selectbox like this:</p> <pre><code>&lt;select id="jform_colors" class="inputbox" multiple="multiple" name="jform[colors][]" aria-invalid="false"&gt; &lt;option value="1"&gt;blue&lt;/option&gt; &lt;option value="2"&gt;yellow&lt;/option&gt; &lt;option value="3"&gt;red&lt;/option&gt; &lt;option value="4"&gt;green&lt;/option&gt; &lt;option value="5"&gt;purple&lt;/option&gt; </code></pre> <p> When I save this colors field, after selecting blue and red for example it gets saved as 1,3 in my database. Joomla does all the work for me... (THANKS Joomla) </p> <p>Now maybe I am getting greedy, but somehow I expect Joomla to preselect these values for me when I edit an entry after saving. It does this with every other type of field, so why not here? Is there anything Im forgetting?</p> <p>Thanks in adv!</p> <p>edit: the bind function in the answer, I tweaked it a bit.</p> <pre><code> public function bind($array, $ignore = '') { if (isset($array['params']) &amp;&amp; is_array($array['params'])) { $registry = new JRegistry(); $registry-&gt;loadArray($array['params']); $array['params'] = (string) $registry; } //print_r($array); if (key_exists('colors', $array) &amp;&amp; is_array($array['colors'])) { echo "pwn"; $array['colors'] = implode(',', $array['colors']); } if (isset($array['metadata']) &amp;&amp; is_array($array['metadata'])) { $registry = new JRegistry(); $registry-&gt;loadArray($array['metadata']); $array['metadata'] = (string) $registry; } return parent::bind($array, $ignore); } </code></pre> <p>And DONT use filter="safehtml" :)</p> <p>Good luck all!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload