From 8efc688ff89ea995c6a1fcd9ba498fa4512db443 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Thu, 4 Mar 2021 16:54:16 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B03750=20data-input-type=20Ajax=20refresh?= =?UTF-8?q?=20:=20use=20`.attr()`=20only=20This=20attributes=20value=20mus?= =?UTF-8?q?t=20be=20get=20using=20`.attr()`=20only,=20and=20never=20.data(?= =?UTF-8?q?)=20This=20is=20what=20we=20adopted=20in=20the=20rest=20of=20th?= =?UTF-8?q?e=20application.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `.data()` method must only be used when dealing with large data structure. When having only strings like here, it is OK to store them in the DOM --- application/cmdbabstract.class.inc.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index e076c6a01..d9985cfc0 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -2446,11 +2446,13 @@ JS // N°3750 refresh container data-input-type attribute if in an Ajax context // indeed in such a case we're only returning the field value content and not the parent container, so we need to update it ! if (utils::IsXmlHttpRequest()) { + // We are refreshing the data attribute only with the .attr() method + // So any consumer that want to get this attribute value MUST use `.attr()` and not `.data()` + // Actually the later uses a dedicated memory (that is initialized by the DOM values on page loading) + // Whereas `.attr()` uses the DOM directly $sHTMLValue .= << -//TODO 3.0.0 should we keep both ? $("[data-input-id='$iId']").attr("data-input-type", "$sInputType"); -$("[data-input-id='$iId']").data("input-type", "$sInputType"); HTML; }