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

Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
052a7e77 by Victor Emanouilov at 2025-08-18T11:55:07+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/052a7e776bfaa9e32df3819bc6b733b4fba1132d

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