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

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68a2ea7eafd28_2cd6d3097258@gitlab-sidekiq-low-urgency-cpu-bound-v2-5d7cc58987-p5smx.mail>

Victor Emanouilov pushed to branch 28.x at Tiki Wiki CMS Groupware / Tiki


Commits:
e0394495 by Victor Emanouilov at 2025-08-18T11:55:21+03:00
[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

- - - - -


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/e039449539451793433931a88fa2ac9c72bd247e

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