[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [BP][ENH] Numeric field: increment option to populate with next value - useful...

"Baraka Kinywa \(@bkinywa24\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68b813d885d12_2cdcfdc703e7@gitlab-sidekiq-low-urgency-cpu-bound-v2-dc78c9688-kpv7c.mail>

Baraka Kinywa pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
0c3027b9 by MAGENE Sem Joel at 2025-09-03T13:01:42+03:00
[BP][ENH] Numeric field: increment option to populate with next value - useful...
---
* [ENH] Numeric field: increment option to populate with next value - useful when we can have repeated values and only want to increment when nothign is specified

(cherry picked from commit 052a7e776bfaa9e32df3819bc6b733b4fba1132d)

See merge request tikiwiki/tiki!8486

- - - - -


1 changed file:

- lib/core/Tracker/Field/Numeric.php


Changes:

=====================================
lib/core/Tracker/Field/Numeric.php
=====================================
@@ -85,6 +85,16 @@ class Tracker_Field_Numeric extends \Tracker\Field\AbstractItemField implements
                             1 => tr('Yes'),
                         ],
                     ],
+                    'incrementWithEmpty' => [
+                        'name' => tr('Increment with empty'),
+                        'description' => tr('Increment the value from the last item in database when the field is empty.'),
+                        'filter' => 'int',
+                        'default' => 0,
+                        'options' => [
+                            0 => tr('No'),
+                            1 => tr('Yes'),
+                        ],
+                    ],
                 ],
             ],
         ];
@@ -139,6 +149,19 @@ class Tracker_Field_Numeric extends \Tracker\Field\AbstractItemField implements
         return $this->renderTemplate('trackerinput/numeric.tpl', $context);
     }
 
+    public function handleSave($value, $oldValue)
+    {
+        if ($this->getOption('incrementWithEmpty') && empty($value)) {
+            $value = TikiLib::lib('trk')->get_maximum_value($this->getConfiguration('fieldId'));
+            if (! $value) {
+                $value = 1;
+            } else {
+                $value += 1;
+            }
+        }
+        return ['value' => $value];
+    }
+
     public function getDocumentPart(Search_Type_Factory_Interface $typeFactory)
     {
         $item = $this->getValue();



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/0c3027b9b087b4a4e65aae527bf8c647357fc6a1

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/0c3027b9b087b4a4e65aae527bf8c647357fc6a1
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.