[TikiWiki-commits] [Git][tikiwiki/tiki][28.x] [BP][FIX] Trackers: Prevent client-side validation on mandatory auto-increment fields

"Sammy Ndabo \(@ndabosam084\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <693d68e8d69cb_2a13695105329d@gitlab-sidekiq-low-urgency-cpu-bound-v2-64d4768b4d-kczcd.mail>

Sammy Ndabo pushed to branch 28.x at Tiki Wiki CMS Groupware / Tiki


Commits:
80c2a08d by Sammy Ndabo at 2025-12-13T13:17:21+00:00
[BP][FIX] Trackers: Prevent client-side validation on mandatory auto-increment fields
---
* [BP][FIX] Trackers: Prevent client-side validation on mandatory auto-increment fields
---
* [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

(cherry picked from commit 4a5d09dc79c0502dca59b98581d394ab72edfdb3)

See merge request tikiwiki/tiki!8590

(cherry picked from commit 2ca1d05555cadbeb0a1839daf3826596a8217729)

See merge request tikiwiki/tiki!9228

- - - - -


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
=====================================
@@ -697,4 +697,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/80c2a08d1da9846e0e346129ad2c72c499757c1b

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/80c2a08d1da9846e0e346129ad2c72c499757c1b
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.