Q - How to add only publish, unpublish options in filter type status of Joomla 5 component ?

Moderator: mindphp

Raja Pdl
PHP VIP Members
PHP VIP Members
โพสต์: 2241
ลงทะเบียนเมื่อ: 27/05/2024 9:50 am

Q - How to add only publish, unpublish options in filter type status of Joomla 5 component ?

โพสต์ที่ยังไม่ได้อ่าน โดย Raja Pdl »

In my Joomla 5 custom component, in filter xml form, I used filter type "status", and by default, it includes "Published", "Unpublished", "Archived", "Trashed" states. But I want to display only Published, and Unpublish.
How can customize Joomla default type="status" to display only "Published" and "Unpublished" options?

โค้ด: เลือกทั้งหมด

<field
            name="published"
            type="status"
            label="JOPTION_SELECT_PUBLISHED"
            >
            <option value="">JOPTION_SELECT_PUBLISHED</option>
</field>
MindPHP Assistant

Re: Q - How to add only publish, unpublish options in filter type status of Joomla 5 component ?

โพสต์ที่ยังไม่ได้อ่าน โดย MindPHP Assistant »

To customize the status filter in your Joomla 5 custom component to display only "Published" and "Unpublished" options, you'll need to avoid using the default `type="status"` field. Instead, define a custom select field that specifies only the desired options.

Here is how you can modify your XML form to achieve this:

โค้ด: เลือกทั้งหมด

xml
<field
    name="published"
    type="list"  <!-- Use 'list' instead of 'status' -->
    label="JOPTION_SELECT_PUBLISHED"
    >
    <option value="1">JPUBLISHED</option>  <!-- Published -->
    <option value="0">JUNPUBLISHED</option>  <!-- Unpublished -->
</field>
### Explanation:

1. **Field Type**: Use `type="list"` instead of `type="status"`. The `status` type in Joomla automatically includes all four states ("Published", "Unpublished", "Archived", "Trashed"). By using `list`, you have full control over the options displayed.

2. **Options**:
- `<option value="1">JPUBLISHED</option>`: This option corresponds to the "Published" state. The language constant `JPUBLISHED` is used to display the localized string for "Published".
- `<option value="0">JUNPUBLISHED</option>`: This option corresponds to the "Unpublished" state. The language constant `JUNPUBLISHED` is used to display the localized string for "Unpublished".

3. **Label**: The label attribute is used to specify a text description for this field, typically a language constant that translates to "Select Published State" or something similar.

By using a `list` type field with specified options, you can customize exactly which statuses are available in your filter dropdown.
Raja Pdl
PHP VIP Members
PHP VIP Members
โพสต์: 2241
ลงทะเบียนเมื่อ: 27/05/2024 9:50 am

Re: Q - How to add only publish, unpublish options in filter type status of Joomla 5 component ?

โพสต์ที่ยังไม่ได้อ่าน โดย Raja Pdl »

fixed by updating the type as list as follows:

โค้ด: เลือกทั้งหมด

        <field
            name="published"
            type="list"
            label="JOPTION_SELECT_PUBLISHED"
            onchange="this.form.submit();"
            >
            <option value="1">JPUBLISHED</option>  
            <option value="0">JUNPUBLISHED</option>  
        </field>
Thank you
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 3