J4.x

Adding custom fields/Checkboxes Field

From Joomla! Documentation

< J4.x:Adding custom fields
Joomla! 
4.x
Tutorial
Custom Fields - Creating a Checkboxes Field


Introduction[edit]

The Checkboxes Field provides one or more checkbox items which can be selected or deselected. It's useful for creating a consistent list of optional attributes for an item.

Creating the field[edit]

We will create a Checkboxes Field for use in our articles.

From the Sidebar Menu in the Backend choose Content then Fields.

Before clicking the New button, check the dropdown list below the New button is set to Article - this is the default setting for use in the Article view.

NOTE: Although this tutorial covers creating a checkboxes field for use in an article, the following steps are the same if you were creating one for use in the Contacts Component (remember to set the view before clicking new), the Users Component, or any other component which supports custom fields..

Click New.

The Field Editor will open on the General tab.

Enter a Title This should be specific to the purpose of the new field. Avoid generic titles in case you want to use other calendar fields in other places.

On the Type field choose Checkboxes.

The Name field will be filled in automatically on saving the field, but you can enter a different one. It should be lowercase and separated by hyphens.

The Label field is automatically set to be the same as the Custom Field Title but you can enter whatever you want. The value you enter is output on the Frontend if you choose to show the Label.

Add a Description if it will be useful. It is not required.

Set the Required Field to Yes or No with the toggle button. Setting to Yes will make the field a required one that cannot be skipped.

The Only Use In Subform field can be set to Yes if you only want the field available as a Subform child field.

The Default Value field can be set to have certain checkboxes checked when the field is first loaded. To check an item by default, enter the value in this field exactly as it appears in the subform below. To check multiple items, add multiple values separated by commas.

Special options within this field are:

  • Checkbox Values: This subform determines what checkboxes are available in an item.
    • Text: This is the text which will be displayed both with the checkbox in the edit form, as well as in the front end if it is selected.
    • Value: This optional field lets you specify the value of the checkbox, which can be used in the Default Value option, the Showon option in other fields, or in layout overrides. This is not displayed to the user or front end.

Please note: if you change the value of any checkbox items after the field is used in items, it could result in data loss. Proceed with caution.

At this point you have entered sufficient information to create the Custom Field and make it available for use.

Save the Custom Field[edit]

Click Save & Close and the Custom Field is available to use.

Using the field in the Backend[edit]

Frontend Output of the Checkboxes Custom Field[edit]

In the Frontend, you can see the field as you see in the following image. The option in Automatic display is responsible for the position of the field and your template is responsible for the layout of the field.

Fields are only displayed in the Frontend if you have filled them with data in the article. If it is not a required field, can you forget it?


Note that the output is displayed with a bullet point - this is the default layout and may look different dependent on your template.

It is possible to change the layout and date format by creating a template custom override.