Skip to content

Commit 07c87ce

Browse files
committed
Added custom error message field
Custom error message field for required input controls.
1 parent f69b17d commit 07c87ce

File tree

10 files changed

+69
-24
lines changed

10 files changed

+69
-24
lines changed

forms/fielditem.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
<option value="1">JYES</option>
4848
<option value="0">JNO</option>
4949
</field>
50+
<field
51+
showon="required:1"
52+
name="custom_error"
53+
type="text"
54+
label="MOD_JDSCF_CUSTOM_ERROR_LBL"
55+
description="Show a custom error message when fields are required."
56+
/>
5057
<field
5158
name="show_label"
5259
type="radio"

language/en-GB/en-GB.mod_jdsimplecontactform.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ MOD_JDSCF_FORM_SUBMIT_DEFAULT="Submit"
5555
MOD_JDSCF_REQUIRED_LBL="Required"
5656
MOD_JDSCF_REQUIRED_DESC="Select to make the input of the field required."
5757

58+
MOD_JDSCF_CUSTOM_ERROR_LBL="Custom Required Error"
59+
MOD_JDSCF_CUSTOM_ERROR_DESC="Enter to show a custom error message when fields are required."
60+
5861
MOD_JDSCF_TYPE_LBL="Type"
5962
MOD_JDSCF_TYPE_DESC="Select the type of the field."
6063

layouts/fields/calendar.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,29 @@
1010
extract($displayData);
1111
$attrs = [];
1212
if (isset($field->placeholder) && !empty($field->placeholder)) {
13-
$attrs[] = 'placeholder="' . $field->placeholder . '"';
13+
$attrs[] = 'placeholder="' . $field->placeholder . '"';
1414
}
1515

1616
if (!empty($field->id)) {
17-
$attrs[] = 'id="' . $field->id . '"';
17+
$attrs[] = 'id="' . $field->id . '"';
1818
}
1919

2020
if ($field->required) {
21-
$attrs[] = 'required';
22-
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
21+
$attrs[] = 'required';
22+
if (!empty(trim($field->custom_error))) {
23+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf($field->custom_error) . '"';
24+
} else {
25+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
26+
}
2327
}
2428

2529
$document = JFactory::getDocument();
2630
$style = 'label.calendar_icon {'
27-
. 'display: inherit;'
28-
. 'cursor: pointer;'
29-
. 'margin: 0px;'
30-
. 'border-radius: 0;'
31-
. '}';
31+
. 'display: inherit;'
32+
. 'cursor: pointer;'
33+
. 'margin: 0px;'
34+
. 'border-radius: 0;'
35+
. '}';
3236
$document->addStyleDeclaration($style);
3337
?>
3438

@@ -45,17 +49,17 @@
4549

4650
<?php
4751
$js = 'var jdscf_picker_' . $module->id . ' = new Pikaday({'
48-
. 'field: document.getElementById("' . $field->id . '")';
52+
. 'field: document.getElementById("' . $field->id . '")';
4953
if (isset($field->calendar_min) && !empty($field->calendar_min) && $field->calendar_min != '0000-00-00 00:00:00') {
50-
$js .= ',minDate: moment("' . $field->calendar_min . '").toDate()';
54+
$js .= ',minDate: moment("' . $field->calendar_min . '").toDate()';
5155
}
5256
if (isset($field->calendar_max) && !empty($field->calendar_max) && $field->calendar_max != '0000-00-00 00:00:00') {
53-
$js .= ',maxDate: moment("' . $field->calendar_max . '").toDate()';
57+
$js .= ',maxDate: moment("' . $field->calendar_max . '").toDate()';
5458
}
5559
if (isset($field->calendar_format) && !empty($field->calendar_format)) {
56-
$js .= ',format: "' . $field->calendar_format . '"';
60+
$js .= ',format: "' . $field->calendar_format . '"';
5761
} else {
58-
$js .= ',format: "MM-DD-YYYY"';
62+
$js .= ',format: "MM-DD-YYYY"';
5963
}
6064

6165
$js .= ',defaultDate: moment("' . date('Y-m-d') . '").toDate(),setDefaultDate:true';

layouts/fields/checkbox.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@
99
defined('_JEXEC') or die;
1010
extract($displayData);
1111
$options = ModJDSimpleContactFormHelper::getOptions($field->options);
12+
13+
// die(print_r(empty(trim($field->custom_error))));
14+
1215
$attrs = [];
1316
if ($field->required) {
1417
$attrs[] = 'required';
15-
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
18+
if (!empty(trim($field->custom_error))) {
19+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf($field->custom_error) . '"';
20+
} else {
21+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
22+
}
1623
}
1724
?>
1825
<div class="form-check form-check-inline">

layouts/fields/checkboxes.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
$attrs = [];
1313
if ($field->required) {
1414
$attrs[] = 'required';
15-
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
15+
if (!empty(trim($field->custom_error))) {
16+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf($field->custom_error) . '"';
17+
} else {
18+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
19+
}
1620
}
1721
$optionslayout = isset($field->optionslayout) ? $field->optionslayout : 'vertical';
1822
?>

layouts/fields/file.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
extract($displayData);
1111
$attrs = [];
1212
if ($field->required) {
13-
$attrs[] = 'required';
14-
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
13+
$attrs[] = 'required';
14+
if (!empty(trim($field->custom_error))) {
15+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf($field->custom_error) . '"';
16+
} else {
17+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
18+
}
1519
}
1620
$attrs[] = 'id="' . $field->name . '-file-input"';
1721
//fetching allowed types

layouts/fields/list.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
$attrs = [];
1313
if ($field->required) {
1414
$attrs[] = 'required';
15-
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
15+
if (!empty(trim($field->custom_error))) {
16+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf($field->custom_error) . '"';
17+
} else {
18+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
19+
}
1620
}
1721
?>
1822
<select name="jdscf[<?php echo $field->name; ?>]" class="form-control" <?php echo implode(' ', $attrs); ?>>

layouts/fields/radio.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
$attrs = [];
1313
if ($field->required) {
1414
$attrs[] = 'required';
15-
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
15+
if (!empty(trim($field->custom_error))) {
16+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf($field->custom_error) . '"';
17+
} else {
18+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
19+
}
1620
}
1721
$optionslayout = isset($field->optionslayout) ? $field->optionslayout : 'vertical';
1822
?>

layouts/fields/text.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@
4747

4848
if ($field->required) {
4949
$attrs[] = 'required';
50-
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
50+
if (!empty(trim($field->custom_error))) {
51+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf($field->custom_error) . '"';
52+
} else {
53+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
54+
}
5155
}
5256
?>
5357
<input type="text" name="jdscf[<?php echo $field->name; ?>][email]" class="form-control" <?php echo implode(' ', $attrs); ?> />

layouts/fields/textarea.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
extract($displayData);
1111
$attrs = [];
1212
if ($field->required) {
13-
$attrs[] = 'required';
14-
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
15-
}
13+
$attrs[] = 'required';
14+
if (!empty(trim($field->custom_error))) {
15+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf($field->custom_error) . '"';
16+
} else {
17+
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
18+
}
19+
}
1620
if (isset($field->placeholder) && !empty($field->placeholder)) {
1721
$attrs[] = 'placeholder="' . $field->placeholder . '"';
1822
}

0 commit comments

Comments
 (0)