[TikiWiki-commits] [Git][tikiwiki/tiki][26.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 <68a2ea9177b53_2cd6c7c230a9@gitlab-sidekiq-low-urgency-cpu-bound-v2-5d7cc58987-4gbgh.mail>

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


Commits:
238c99ec by Victor Emanouilov at 2025-08-18T11:55:40+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\AbstractField implements \Tra
                             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'),
+                        ],
+                    ],
                 ],
             ],
         ];
@@ -130,6 +140,19 @@ class Tracker_Field_Numeric extends \Tracker\Field\AbstractField implements \Tra
         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/238c99ec02e332a8822c9892d47fca23d2b85811

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