Introduction

Sometimes, we hope to get A items list as selector in B edit interface. In the past, we have to use sql to query this list and build as a HTML <select>. In windwalker, every MVC have their own list and modal formfield. We can add them in XML anytime.

Basic List Modal

We look sakura first, there is two files in:

  • model/field/sakura/list.php
  • model/field/sakura/modal.php

List

Now we can use sakura_list to fetch sakura items as a select list.

<field name="sakura_id"
    type="sakura_list"
    label="Select Sakura"
    description="COM_FLOWER_SELECT_SAKURA_DESC"
>
    <option>JOPTION_DO_NOT_USE</option>
</field>

In config.xml, we need include fields:

<fieldset
    name="component"
    addfieldpath="administrator/components/com_flower/model/field"
>

Result

img

Modal

Same as list, we use sakura_modal to select sakuras:

<field name="sakura_id"
    type="sakura_modal"
    label="Select Sakura"
    description="COM_FLOWER_SELECT_SAKURA_DESC"
/>

img

img

Using some attributes to target other extensions or table

List

We can using itemlist to choose table items from other extension, Foe example, if we want to get city list in com_address, so we can use this xml:

<field name="city_id"
    type="itemlist"
    label="Select City"

    extension="com_address"
    view_list="cities"
    view_item="city"
>
    <option>JOPTION_DO_NOT_USE</option>
</field>

The Itemlist formfield will get #__addresses_cities table as list source.

Modal

Same as itemlist.

<field name="city_id"
    type="modal"
    label="Select City"

    extension="com_address"
    view_list="cities"
    view_item="city"
>
    <option>JOPTION_DO_NOT_USE</option>
</field>

Note: Our view need modal.php in view tmpl folder taht we can get this modal work.

Extends ItemList and Modal formfield

We can see Sakura_list first:

// model/field/sakura/list.php

include_once JPATH_LIBRARIES . '/windwalker/src/init.php';
JForm::addFieldPath( AKPATH_FORM.'/fields');
JFormHelper::loadFieldClass('itemlist');

class JFormFieldSakura_List extends JFormFieldItemlist
{
    public $type = 'Sakura_List';

    public $value = null;

    public $name = null;

    protected $view_list = 'sakuras' ;

    protected $view_item = 'sakura' ;

    protected $extension = 'com_flower' ;
}

It's very simple, this class extends from JFormFieldItemlist, and add $view_list, $view_item , $extension three properties then formfield will auto fetch lst we want.

If you need more functions, please override getOptions() ans setElement().

Quick Add

Add these attributes in xml:

<field name="sakura_list"
     type="sakura_list"
     label="Select Sakura"

     quickadd="true"
>
    <option>JOPTION_DO_NOT_USE</option>
 </field>

Now we'll see quickadd button.

img

Click and enter input.

img

Now quickadd will use ajax to add new item.

img

Customize QuickAdd fields

In model/form/sakura.xml, we'll see this fields:

<!-- For Quick Ajax AddNew -->
<fieldset name="quickadd">
    <field name="title"
        type="text"
        label="JGLOBAL_TITLE"
        description="JFIELD_TITLE_DESC"
        required="true"
        size="50"
        class="input-xlarge"
        />

    <field name="catid"
        type="category"
        label="JCATEGORY"
        description="JFIELD_CATEGORY_DESC"
        extension="com_flower"
        >
        <option value="0">COM_FLOWER_TITLE_UNCATEGORISED</option>
    </field>

    <field name="state"
        type="list"
        label="State"
        >
        <option value="0">Unpublished</option>
        <option value="1">Published</option>
    </field>
</fieldset>

Just add field here, fieldname should same as sql column. The new field will appear in modal box.

img

QuickAdd attributes

Attribute Description
task Using which task (controller) to handle quickadd ajax.
quickadd Need TRUE to enable this function.
table Database table name, default is #__{component}_{view_list}
key_field Select option value.
value_field Select option text.
formpath Quickadd form xml path. Default is model/form/{view_item}.xml
quickadd_handler Which component get our ajax to handle quickadd, need windwalker component.
title Quickadd modal box and button title.

Found a typo? Help us improve this document.

This document is for Windwalker Joomla RAD, if you are finding Windwalker PHP framework, please see: Windwalker Framework