[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [BP][FIX] Skip parameter filtering for plugin aliases to preserve user arguments

"Baraka Kinywa \(@bkinywa24\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68daeb1d768f0_2c3cff2894a9@gitlab-sidekiq-low-urgency-cpu-bound-v2-5cc58485fb-qps2p.mail>

Baraka Kinywa pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki


Commits:
543beba2 by Aksanti Bahiga at 2025-09-29T23:18:13+03:00
[BP][FIX] Skip parameter filtering for plugin aliases to preserve user arguments
---
* [BP][FIX] Skip parameter filtering for plugin aliases to preserve user arguments
---
* [BP][FIX] Skip parameter filtering for plugin aliases to preserve user arguments
---
* [FIX] Skip parameter filtering for plugin aliases to preserve user arguments
---
* [FIX] Add validation

* [FIX] Add validation

* [FIX] Skip parameter filtering for plugin aliases to preserve user arguments

See merge request tikiwiki/tiki!8366

See merge request tikiwiki/tiki!8657

(cherry picked from commit 120b9b246379b90b552cbaeade4581172b5e2164)

See merge request tikiwiki/tiki!8673

See merge request tikiwiki/tiki!8676

- - - - -


2 changed files:

- lib/jquery_tiki/tiki-admin.js
- templates/admin/include_textarea.tpl


Changes:

=====================================
lib/jquery_tiki/tiki-admin.js
=====================================
@@ -67,7 +67,7 @@
         $(".add-param", $pluginAliasAdmin).on("click", function () {
             var $fieldset = $(this).closest("fieldset");
             // for composed args/params (fieldset) the template comes after the one for a new param,
-                // so we need closestDescendent, not :first
+            // so we need closestDescendent, not :first
             var $template = $fieldset.closestDescendent(".param.d-none");
             // If no proper template found, use the first visible param as fallback
             if ($template.length === 0) {
@@ -76,31 +76,61 @@
             }
             var $clone = $template.clone(true),
                 index = $fieldset.find(".param:visible").length;
-            $clone
-                .find("input")
-                .each(function () {
-                    const $input = $(this);
-                    const name = $input.attr("name");
-                    if (name && name.includes("__NEW__")) {
-                        const newName = name.replace("__NEW__", index);
-                        $input.attr("name", newName);
-                    } else if (name) {
-                        // For fallback cloning, update the index in existing names
-                        const newName = name.replace(/\[(\d+)\]/, `[${index}]`);
-                        $input.attr("name", newName);
-                    }
-                    $input.val("");
-                });
-
+            $clone.find("input").each(function () {
+                const $input = $(this);
+                const name = $input.attr("name");
+                const id = $input.attr("id");
+                // Update id if present
+                if (id && id.includes("__NEW__")) {
+                    const newId = id.replace("__NEW__", index);
+                    $input.attr("id", newId);
+                } else if (id) {
+                    // For fallback cloning, update the index in existing ids
+                    const newId = id.replace(/\[(\d+)\]/g, `[${index}]`);
+                    $input.attr("id", newId);
+                }
+                // Update name if present
+                if (name && name.includes("__NEW__")) {
+                    const newName = name.replace("__NEW__", index);
+                    $input.attr("name", newName);
+                } else if (name) {
+                    // For fallback cloning, update the index in existing names
+                    const newName = name.replace(/\[(\d+)\]/g, `[${index}]`);
+                    $input.attr("name", newName);
+                }
+                $input.val("");
+                if($input.data("required")){
+                    $input.attr("required", true);
+                }
+            });
             $clone.find(".d-none").addBack().removeClass("d-none");
 
             if (jqueryTiki.autocomplete && jqueryTiki.ui) {
                 var plugin = $("#implementation").data("plugin");
 
-                if (plugin) {
-                    // get the param names
-                    var params = $.map(plugin.params, function(element,index) {return index;});
-
+            if (plugin) {
+                    const params = Object.keys
+                    (plugin.params || {});
+                if (window.elementPlus?.autocomplete) {
+                    // get the input element
+                    const inputElement = $clone.find("input.sparam-default");
+                    autocomplete(inputElement[0], null, {
+                        source: params,
+                        select: function (event) {
+                            const value = event.detail[0];
+                            const defInput = $(this).closest(".param").find("input.sparam-default");
+                            const param = plugin.params[value];
+                            const options = [];
+                            $.each(param.options, function (k, v) {
+                                options.push(v.value);
+                            });
+                            defInput.val(param.default);
+                            if (options.length) {
+                                autocomplete(defInput, null, { source: options });
+                            }
+                        },
+                    });
+                } else if (jqueryTiki.autocomplete && jqueryTiki.ui) {
                     $clone.find("input.sparam-name").autocomplete({
                         minLength: 1,
                         source: params,
@@ -129,12 +159,60 @@
                     });
                 }
             }
-
+        }
             $template.parent().append($clone);    //  .tiki_popover() doesn't work as the title has been removeed on page
                 // load... FIXME?;
-
+            // Attach validation to the new field added
+            $clone.find(".sparam-name").each(function () {
+                attachValidation($(this));
+            });
             return false;
         });
+       // Custom validation: each sparam must have documentation
+        $.validator.addMethod("hasAssociatedDocumentation", function (value, element) {
+            const paramName = value.trim(); // use the field value directly
+            if (!paramName) return true;
+            // Look for any doc input whose value matches the param name
+            const documentationField = $(`#pluginalias_doc input`).filter(function () {
+                return $(this).val().trim() === paramName;
+            });
+            return documentationField.length > 0;
+        }, "* This argument must have an associated documentation.");
+
+        var $pluginAliasForm = $pluginAliasAdmin.closest('form.admin');
+        // Adding validation with jquery validate
+        $pluginAliasForm.validate({
+            errorClass: "invalid-feedback",
+        });
+
+        // Helper to attach validation to a field
+        function attachValidation($field) {
+            $field.rules("add", {
+                hasAssociatedDocumentation: true
+            });
+        }
+
+        // On page load, attach to existing sparam-name fields
+        $pluginAliasForm.find(".sparam-name").each(function() {
+            attachValidation($(this));
+        });
+
+        // Handle submit properly
+        $pluginAliasForm.on("submit", function (e) {
+            if (!$pluginAliasForm.valid()) {
+                e.preventDefault(); // block submit if invalid
+                // add a scroll to the first error
+                const $firstError = $pluginAliasForm.find(".invalid-feedback").first();
+                if ($firstError.length) {
+                    $("html, body").animate(
+                        {
+                            scrollTop: $firstError.offset().top - 100,
+                        },
+                        500
+                    );
+                }
+            }
+        });
 
         $($pluginAliasAdmin).on("click", ".delete-param", function (e) {
             e.preventDefault();
@@ -374,8 +452,13 @@
 
     $('.input-pref_filters').on("change", function () {
         const pref_filters_values = $("input[name='pref_filters[]']:checked").map(function () {
-            return $(this).val();
-        }).get();
+                return $(this).val();
+            }).get();
+
+        // Synchronize page-level toggle with navbar checkboxes
+         const advancedChecked = pref_filters_values.includes('advanced');
+        $('.preffilter-toggle').prop("checked", advancedChecked);
+
         $("#preffilter-loader").removeClass('d-none');
         $.ajax("tiki-admin.php", {
             type: 'POST',
@@ -397,3 +480,4 @@
     });
 
 })(jQuery);
+


=====================================
templates/admin/include_textarea.tpl
=====================================
@@ -438,7 +438,7 @@
                                 {elseif $token eq '__NEW__'}
                                     <div class="mb-3 row d-none param">
                                         <div class="col-sm-6">
-                                            <input class="form-control sparam-name" type="text" name="sparams[__NEW__][token]" value="" placeholder="{tr}Name{/tr}">
+                                            <input class="form-control sparam-name d-none" type="text" name="sparams[__NEW__][token]" value="" placeholder="{tr}Name{/tr}" data-required="true">
                                         </div>
                                         <div class="col-sm-5">
                                             <input class="form-control sparam-default" type="text" name="sparams[__NEW__][default]" value="" placeholder="{tr}Default Value{/tr}">
@@ -465,7 +465,7 @@
                                             {tr}Parameter{/tr}
                                         </label>
                                         <div class="col-sm-7">
-                                            <input class="form-control" type="text" name="input[{$token|escape}][token]" id="input[{$token|escape}][token]" value="{if $token neq '__NEW__'}{$token|escape}{/if}">
+                                            <input class="form-control {if $token eq '__NEW__'} d-none{/if}" type="text" name="input[{$token|escape}][token]" id="input[{$token|escape}][token]" value="{if $token neq '__NEW__'}{$token|escape}{/if}" data-required="true">
                                         </div>
                                         <div class="col-sm-1">
                                             {icon name='delete' class='text-danger delete-param tips btn btn-link' title="{tr}Delete this parameter's documentation{/tr}"}
@@ -476,7 +476,7 @@
                                             {tr}Name{/tr}
                                         </label>
                                         <div class="col-sm-8">
-                                            <input class="form-control" type="text" name="input[{$token|escape}][name]" id="input[{$token|escape}][name]" value="{$detail.name|escape}">
+                                            <input class="form-control {if $token eq '__NEW__'} d-none{/if}" type="text" name="input[{$token|escape}][name]" id="input[{$token|escape}][name]" value="{$detail.name|escape}" data-required="true">
                                         </div>
                                     </div>
                                     <div class="mb-3 row">
@@ -550,7 +550,7 @@
                                                 {tr}Parameter{/tr}
                                             </label>
                                             <div class="col-sm-5">
-                                                <input class="form-control {if $token eq '__NEW__'} d-none{/if}" type="text" name="bodyparam[{$token|escape}][token]" id="bodyparam[{$token|escape}][token]" value="{if $token neq '__NEW__'}{$token|escape}{/if}">
+                                                <input class="form-control {if $token eq '__NEW__'} d-none{/if}" type="text" name="bodyparam[{$token|escape}][token]" id="bodyparam[{$token|escape}][token]" value="{if $token neq '__NEW__'}{$token|escape}{/if}" data-required="true">
                                             </div>
                                             <div class="col-sm-1">
                                                 {icon name='delete' class='text-danger delete-param tips btn btn-link' title="{tr}Delete this body parameter{/tr}"}



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/543beba27c7f3d4d7aa1d074134eda4b1b5d3666

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