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

"Jonny Bradley \(@jonnybradley\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68efcfcfc6aa6_2ce0bdc3143e@gitlab-sidekiq-low-urgency-cpu-bound-v2-bfcdd4b4d-nt6bt.mail>

Jonny Bradley pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki


Commits:
c97896b4 by Jonny Bradley at 2025-10-15T16:39:48+00:00
[BP][FIX] Trackers Rules: fix all the fields of a Tracker on which the Rules do not work
---
* [BP][FIX] Trackers Rules: fix all the fields of a Tracker on which the Rules do not work
---
* [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


(cherry picked from commit 2750ffbb4fb9a9d29f6bd8557f76634d7d8624f4)

c53f3b2f [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!8787


(cherry picked from commit 6f143be81f1ce997c2ea5ef1419d0c2b266c819a)

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

Co-authored-by: Jonny Bradley <[email protected]>

See merge request tikiwiki/tiki!8788

- - - - -


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
=====================================
@@ -1305,7 +1305,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
=====================================
@@ -222,7 +222,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
=====================================
@@ -187,7 +187,7 @@ addScopedStyleIdentifier(vm, \"$scopedStyleIdentifier\");
         return $appHtml;
     }
 
-    public function generateTrackerRulesJS($fields, $parentSelector = '.tracker-field-group:first')
+    public function generateTrackerRulesJS($fields, $parentSelector = '.tracker-field-group:first', $isInEditContext = false)
     {
 
         $js = '';
@@ -197,7 +197,7 @@ addScopedStyleIdentifier(vm, \"$scopedStyleIdentifier\");
         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/c97896b4090a1c6db1870c835698ab03162762db

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