In this tutorial, we'll walk through the process of adding a datetime field to your forms. This method allows you to easily integrate datetime inputs into your forms. We will cover how to:
This method adds a datetime input field to your form, taking three parameters:
This example shows how to add a datetime field to your form.
// Adding a datetime field
$objConfig->datetime('field_name', 'field_label', $required = 0);
To ensure the inputted datetime exceeds the datetime inputted in another field on the same form, you can chain the exceedField()
method after the datetime()
method. This example shows how to add such validation.
// Adding a datetime field that must exceed the 'other_datetime_field' field
$objConfig->datetime('field_name', 'field_label', $required = 0)->exceedField('other_datetime_field');
To ensure the inputted datetime does not exceed a certain datetime inputted in another field on the same form, you can use the notExceedField()
method. This example shows how to add a datetime field with such validations.
// Adding a datetime field that must not exceed the 'other_datetime_field' field
$objConfig->datetime('field_name', 'field_label', $required = 0)->notExceedField('other_datetime_field');
To set the default datetime as the current date, you can chain the xdefault()
method after the datetime()
method. This example shows how to add a date field with the current datetime set as the default value.
// Adding a required datetime field with the current date as default
$objConfig->datetime('field_name', 'field_label', $required = 0)->xdefault(date('Y-m-d H:i'));
To set the minimum year for the date field, you can chain the min()
method after the datetime()
method. This example shows how to add a date field with a minimum year that is 14 years before the current year.
// Adding a required datetime field with a minimum year that is 14 years before the current year
$objConfig->datetime('field_name', 'field_label', $required = 0)->min(14);
To set the maximum year for the date field, you can chain the max()
method after the datetime()
method. This example shows how to add a datetime field with a maximum year that is 5 years from the current year.
// Adding a required datetime field with a maximum year that is 5 years from the current year
$objConfig->datetime('field_name', 'field_label', $required = 0)->max(5);
For the configuration to work properly, it's important to include the 'field_name' amongst the addFields
and editFields
. This ensures that the datetime fields are correctly initialized and integrated into your form. This example shows how to configure the add and edit fields.
// Adding your datetime field to the add and edit forms
$objConfig->addFields(array('field_name'));
$objConfig->editFields(array('field_name'));
This tutorial provided a comprehensive overview of integrating datetime fields into your forms using the configuration method $objConfig->datetime()
. Key features covered include:
By following these guidelines, you can effectively manage datetime inputs in your forms and ensure data integrity in your applications. If you have specific requirements or need further customization, feel free to adapt these methods to suit your component's needs.
Your download is here.