[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [BP][FIX] Trackers Rules: fix all the fields of a Tracker on which the Rules do not work

"Joel Mpunga \(@joelmpunga79\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68b83f8851090_2cdcf78176d@gitlab-sidekiq-low-urgency-cpu-bound-v2-799dc879cb-ldgnf.mail>

Joel Mpunga pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
2750ffbb by Joel Mpunga at 2025-09-03T13:07:47+00:00
[BP][FIX] Trackers Rules: fix all the fields of a Tracker on which the Rules do not work
---
* [FIX] Trackers Rules: fix all the fields of a Tracker on which the Rules do not work
---
* [FIX]Trackers Rules :fix all the fields of a Tracker on which the Rules do not work

See merge request tikiwiki/tiki!7353


(cherry picked from commit 8786ba5b10235b51c272fd41d3efd9065097b78d)

63422970 [FIX]Trackers Rules :fix all the fields of a Tracker on which the Rules do not work

Co-authored-by: Joel Mpunga <[email protected]>

See merge request tikiwiki/tiki!8376

- - - - -


9 changed files:

- lib/core/Services/Tracker/Controller.php
- lib/core/Tracker/Field/EmailFolder.php
- lib/core/Tracker/Field/GeographicFeature.php
- lib/core/Tracker/Rule/Rules.php
- lib/vue/vuejslib.php
- templates/trackerinput/autoincrement.tpl
- templates/trackerinput/statictext.tpl
- templates/trackeroutput/computed.tpl
- templates/trackeroutput/usergroups.tpl


Changes:

=====================================
lib/core/Services/Tracker/Controller.php
=====================================
@@ -1326,7 +1326,8 @@ class Services_Tracker_Controller
         }
 
         if ($prefs['tracker_field_rules'] === 'y') {
-            $js = TikiLib::lib('vuejs')->generateTrackerRulesJS($definition->getFields());
+            $js = TikiLib::lib('vuejs')->generateTrackerRulesJS(fields: $definition->getFields(), isInEditContext: true);
+            //$js = TikiLib::lib('vuejs')->generateTrackerRulesJS($definition->getFields(), '', true);
             TikiLib::lib('header')->add_jq_onready($js);
         }
 


=====================================
lib/core/Tracker/Field/EmailFolder.php
=====================================
@@ -249,7 +249,11 @@ class Tracker_Field_EmailFolder extends Tracker_Field_Files implements \Tracker\
 
     public function renderInput($context = [])
     {
-        return tr("Emails can be copied or moved here via the Webmail interface.");
+        $ins_id = $this->getInsertId();
+        //This input is useful for facilitating the execution of rules
+        $hiddenInput = "<input type='hidden' name='$ins_id'>";
+        $translatedText = tr("Emails can be copied or moved here via the Webmail interface.");
+        return $hiddenInput . $translatedText;
     }
 
     public function renderOutput($context = [])


=====================================
lib/core/Tracker/Field/GeographicFeature.php
=====================================
@@ -43,7 +43,11 @@ class Tracker_Field_GeographicFeature extends \Tracker\Field\AbstractItemField i
 
     public function renderInput($context = [])
     {
-        return tr('Feature cannot be set or modified through this interface.');
+        $ins_id = $this->getInsertId();
+        //This input is useful for facilitating the execution of rules
+        $hiddenInput = "<input type='hidden' name='$ins_id'>";
+        $translatedText = tr("Feature cannot be set or modified through this interface.");
+        return $hiddenInput . $translatedText;
     }
 
     public function renderOutput($context = [])


=====================================
lib/core/Tracker/Rule/Rules.php
=====================================
@@ -39,7 +39,7 @@ class Rules
      *
      * @return string
      */
-    public function getJavaScript(string $parentSelector, array $field): string
+    public function getJavaScript(string $parentSelector, array $field, $isInEditContext = false): string
     {
         global $prefs;
 
@@ -70,8 +70,14 @@ class Rules
             $operator = ' || ';
         }
 
+        if ($isInEditContext) {
+            $selectorAttribute = 'name';
+        } else {
+            $selectorAttribute = 'name^';
+        }
+
         foreach ($this->conditions->predicates as $predicate) {
-            $selector = '[name=\'' . $predicate->target_id . '\']' . $conditionQualifier;
+            $selector = "[$selectorAttribute='{$predicate->target_id}']$conditionQualifier";
             $selectors[] = $selector;
             if (
                 in_array($field['type'], ['R', 'M']) ||
@@ -92,7 +98,8 @@ class Rules
 
         foreach ($this->actions->predicates as $predicate) {
             if ($predicate->operator_id !== 'NoOp') {
-                $targetSelector = "\$(\"[name='{$predicate->target_id}']\", $(this).closest(\"form\")).last()";
+                $targetSelector = "\$(\"[{$selectorAttribute}='{$predicate->target_id}']\", \$(this).closest(\"form\")).last()";
+
                 $actions[]
                     = "    if ($targetSelector.length === 0) { console.error('Tracker Rules: element $predicate->target_id not found'); return; }";
                 if (strpos($predicate->operator_id, 'Required') === false) {
@@ -113,7 +120,7 @@ class Rules
         if ($this->else->predicates) {
             foreach ($this->else->predicates as $predicate) {
                 if ($predicate->operator_id !== 'NoOp') {
-                    $targetSelector = "\$(\"[name='{$predicate->target_id}']\", $(this).closest(\"form\")).last()";
+                    $targetSelector = "\$(\"[{$selectorAttribute}='{$predicate->target_id}']\", \$(this).closest(\"form\")).last()";
                     $else[]
                         = "    if ($targetSelector.length === 0) { console.error('Tracker Rules: element $predicate->target_id not found'); return; }";
                     if (strpos($predicate->operator_id, 'Required') === false) {


=====================================
lib/vue/vuejslib.php
=====================================
@@ -162,7 +162,7 @@ class VueJsLib
         return  '<div id="' . $singleSpaDomId . '" class="tracker-rules"></div>';
     }
 
-    public function generateTrackerRulesJS($fields, $parentSelector = '.tracker-field-group:first')
+    public function generateTrackerRulesJS($fields, $parentSelector = '.tracker-field-group:first', $isInEditContext = false)
     {
 
         $js = '';
@@ -172,7 +172,7 @@ class VueJsLib
         foreach (array_filter($fields) as $field) {
             if (! empty($field['rules']) && $field['rules'] !== '{"conditions":null,"actions":null,"else":null}') {
                 $rules = Tiki\Lib\core\Tracker\Rule\Rules::fromData($field['fieldId'], $field['rules']);
-                $js .= $rules->getJavaScript($parentSelector, $field);
+                $js .= $rules->getJavaScript($parentSelector, $field, $isInEditContext);
             }
         }
 


=====================================
templates/trackerinput/autoincrement.tpl
=====================================
@@ -1,3 +1,4 @@
+<input type="hidden" name="{$field.ins_id}">
 {if !empty($item.itemId)}
     <div{if $field.options_map.prepend or $field.options_map.append} class="input-group"{/if}>
         {if !empty($field.options_map.prepend)}


=====================================
templates/trackerinput/statictext.tpl
=====================================
@@ -1,3 +1,4 @@
+<input type="hidden" name="{$field.ins_id}">
 {if $field.options_array[0] eq 1 or $field.options_array[0] eq 2}
     {$field.value}
 {elseif $field.options_array[1] ne '' and $list_mode eq 'y'}


=====================================
templates/trackeroutput/computed.tpl
=====================================
@@ -1,3 +1,4 @@
+<input type="hidden" name="{$field.ins_id}">
 {if $prefs.trackerfield_computed eq 'y'}
     {if isset($field.computedtype) and $field.computedtype eq 'duration'}
         {if !empty($field.value)}


=====================================
templates/trackeroutput/usergroups.tpl
=====================================
@@ -1,3 +1,4 @@
+<input type="hidden" name="{$field.ins_id}">
 {foreach from=$field.groups item=val name=ix}
     <div>
         {$val|escape}



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/2750ffbb4fb9a9d29f6bd8557f76634d7d8624f4

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