[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Resetting preferences to default values hides the input but the values remain unchanged

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68dc02dcecefa_2cdf63887497@gitlab-sidekiq-low-urgency-cpu-bound-v2-789674d597-s7nkd.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
0b1cbdc0 by Merci Jacob at 2025-09-30T16:10:14+00:00
[FIX] Resetting preferences to default values hides the input but the values remain unchanged
---
* [FIX] Resetting preferences to default values hides the input but the values remain unchanged

See merge request tikiwiki/tiki!8686

- - - - -


3 changed files:

- lib/jquery_tiki/tiki-jquery.js
- src/js/vue-widgets/element-plus-ui/src/helpers/select/applySelect.js
- src/js/vue-widgets/element-plus-ui/src/tests/helpers/select/applySelect.test.js


Changes:

=====================================
lib/jquery_tiki/tiki-jquery.js
=====================================
@@ -4036,7 +4036,7 @@ $(document).on('click', '.pref-reset-wrapper a', function () {
 
 $(document).on('click', '.pref-reset', function() {
     var c = $(this).prop('checked');
-    var $el = $(this).closest('.adminoptionbox').find('input:not(:hidden),select,textarea')
+    var $el = $(this).closest('.adminoptionbox').find('input,select,textarea')
         .not('.system').attr( 'disabled', c )
         .css("opacity", c ? .6 : 1 );
     var defval = $(this).data('preference-default');
@@ -4047,6 +4047,7 @@ $(document).on('click', '.pref-reset', function() {
     } else {
         $(this).data('preference-default', $el.val());
         $el.val(defval);
+        $(`#${$el.attr('element-plus-ref')}`).attr('value', defval); // also reset element-plus if applicable
     }
     $el.trigger("change");
 });


=====================================
src/js/vue-widgets/element-plus-ui/src/helpers/select/applySelect.js
=====================================
@@ -23,8 +23,16 @@ export function observeSelectElementMutations(select, elementPlusUi) {
                     $(elementPlusUi).removeAttr("is-invalid");
                 }
             } else if (mutation.attributeName) {
+                let attributeValue = mutation.target.getAttribute(mutation.attributeName);
                 const attributeName = mutation.attributeName.replace("data-", "");
-                $(elementPlusUi).attr(attributeName, mutation.target.getAttribute(mutation.attributeName));
+                // skip "display: none;" value in the style attribute change
+                if (mutation.attributeName === "style") {
+                    attributeValue = mutation.target
+                        .getAttribute(mutation.attributeName)
+                        .replace(/display:\s*none;?/g, "")
+                        .trim();
+                }
+                $(elementPlusUi).attr(attributeName, attributeValue);
             }
         });
     }).observe(select, { childList: true, attributes: true });


=====================================
src/js/vue-widgets/element-plus-ui/src/tests/helpers/select/applySelect.test.js
=====================================
@@ -8,13 +8,16 @@ describe("applySelect helper functions", () => {
     });
 
     test.each([
-        ["is-invalid", ["class", "is-invalid", "true"]],
-        ["is-invalid", ["class", "", null]],
-        ["max", ["data-max", "2", "2"]],
-        ["max", ["data-max", "", ""]],
+        ["is-invalid", ["is-invalid", "class", "is-invalid", "true"]],
+        ["is-invalid", ["is-invalid", "class", "", null]],
+        ["max", ["max", "data-max", "2", "2"]],
+        ["max", ["max", "data-max", "", ""]],
+        ["style", ["style", "style", "color: red;", "color: red;"]],
+        ["style ('display: none' ignored)", ["style", "style", "display: none;", ""]],
+        ["style ('display: none' ignored but other styles considered)", ["style", "style", "display: none; color: red;", "color: red;"]],
     ])(
         "observeSelectElementMutations is able to update the element-plus-ui %s attribute when relative changes occurs in the select element",
-        async (attribute, [selectAttribute, attributeValue, expectedValue]) => {
+        async (_, [elementPlusAttribute, selectAttribute, attributeValue, expectedValue]) => {
             const givenSelect = document.createElement("select");
             const givenElementPlusUi = document.createElement("element-plus-ui");
             document.body.append(givenSelect, givenElementPlusUi);
@@ -23,12 +26,12 @@ describe("applySelect helper functions", () => {
 
             await window.happyDOM.waitUntilComplete();
 
-            expect(givenElementPlusUi.getAttribute(attribute)).toBeNull();
+            expect(givenElementPlusUi.getAttribute(elementPlusAttribute)).toBeNull();
 
             givenSelect.setAttribute(selectAttribute, attributeValue);
             await window.happyDOM.waitUntilComplete();
 
-            expect(givenElementPlusUi.getAttribute(attribute)).toBe(expectedValue);
+            expect(givenElementPlusUi.getAttribute(elementPlusAttribute)).toBe(expectedValue);
         }
     );
 



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/0b1cbdc0bfd4abc48d86e71f166ea03f4169105f

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