[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Trackers: Prevent client-side validation on mandatory auto-increment fields
Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <68c8576eb6a45_2c63b3dcc87338@gitlab-sidekiq-low-urgency-cpu-bound-v2-679dd6fdf9-g472k.mail> |
Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
4a5d09dc by MAGENE Sem Joel at 2025-09-15T18:06:07+00:00
[FIX] Trackers: Prevent client-side validation on mandatory auto-increment fields
---
* [FIX] Trackers: Prevent client-side validation on mandatory auto-increment fields
See merge request tikiwiki/tiki!8568
- - - - -
3 changed files:
- lib/core/Tracker/Field/AbstractItemField.php
- lib/core/Tracker/Field/AutoIncrement.php
- lib/validatorslib.php
Changes:
=====================================
lib/core/Tracker/Field/AbstractItemField.php
=====================================
@@ -698,4 +698,16 @@ abstract class AbstractItemField implements ItemFieldInterface, IndexableInterfa
{
return '';
}
+ /**
+ * Determines if a field, when marked as mandatory, should be validated
+ * on the client-side (in browser JavaScript).
+ *
+ * @return bool True if client-side validation should apply, false otherwise.
+ */
+ public function isClientSideMandatory(): bool
+ {
+ // By default, all mandatory fields are validated on the client side.
+ // Specific field types can override this behavior.
+ return true;
+ }
}
=====================================
lib/core/Tracker/Field/AutoIncrement.php
=====================================
@@ -137,6 +137,18 @@ class Tracker_Field_AutoIncrement extends \Tracker\Field\AbstractItemField imple
];
}
+ /**
+ * Overrides the default client-side validation behavior.
+ * An auto-increment field's value is generated on the server, so it should
+ * never be considered mandatory by client-side JavaScript validation.
+ *
+ * @return bool Always returns false.
+ */
+ public function isClientSideMandatory(): bool
+ {
+ return false;
+ }
+
public function getTabularSchema()
{
$schema = new Tracker\Tabular\Schema($this->getTrackerDefinition());
=====================================
lib/validatorslib.php
=====================================
@@ -85,7 +85,7 @@ class Validators
} else {
$validationjs .= '"' . $field_name . '"' . ': { ';
}
- if ($isMandatory) {
+ if ($isMandatory && $handler->isClientSideMandatory()) {
if ($field_value['type'] == 'D') {
$validationjs .= 'required_in_group: [1, ".group_' . $field_name . '", "other"], ';
} elseif ($field_value['type'] == 'A') {
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/4a5d09dc79c0502dca59b98581d394ab72edfdb3
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/4a5d09dc79c0502dca59b98581d394ab72edfdb3
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs