Difference between revisions of "Joomla 4 Tips and Tricks: Check two dates"

From Joomla! Documentation

(Started page)
 
m (Added form xml fragmeants)
Line 2: Line 2:
  
 
This code was created for an application that has events with start and end dates that must be less than 30 days apart. Although a multilingual site, the Administrators are obliged to use English so string constant translation has been omitted. The code is for the Administrator data entry form.
 
This code was created for an application that has events with start and end dates that must be less than 30 days apart. Although a multilingual site, the Administrators are obliged to use English so string constant translation has been omitted. The code is for the Administrator data entry form.
 +
 +
== The form XML file ==
 +
 +
The dates are required calendar fields. Note that validation is passed as a custom class starting with validate-.
 +
 +
<source lang="xml">
 +
... other elements ...
 +
<field
 +
name="date_start"
 +
type="calendar"
 +
label="COM_THINGY_CAMP_DATE_START_LABEL"
 +
description="COM_THINGY_CAMP_DATE_START_DESC"
 +
class="w-25 validate-date_start"
 +
required="required"
 +
>
 +
</field>
 +
 +
<field
 +
name="date_end"
 +
type="calendar"
 +
label="COM_THINGY_CAMP_DATE_END_LABEL"
 +
description="COM_THINGY_CAMP_DATE_END_DESC"
 +
class="w-25 validate-date_end"
 +
required="required"
 +
>
 +
</field>
 +
... other elements ...
 +
</source>

Revision as of 19:46, 22 April 2021

Introduction

This code was created for an application that has events with start and end dates that must be less than 30 days apart. Although a multilingual site, the Administrators are obliged to use English so string constant translation has been omitted. The code is for the Administrator data entry form.

The form XML file

The dates are required calendar fields. Note that validation is passed as a custom class starting with validate-.

		... other elements ...
		<field
			name="date_start"
			type="calendar"
			label="COM_THINGY_CAMP_DATE_START_LABEL"
			description="COM_THINGY_CAMP_DATE_START_DESC"
			class="w-25 validate-date_start"
			required="required"
			>
		</field>

		<field
			name="date_end"
			type="calendar"
			label="COM_THINGY_CAMP_DATE_END_LABEL"
			description="COM_THINGY_CAMP_DATE_END_DESC"
			class="w-25 validate-date_end"
			required="required"
			>
		</field>
		... other elements ...