]> _ Git - fluidbook-html5.git/commitdiff
wait #7898 @1:30
authorsoufiane <soufiane@cubedesigners.com>
Wed, 21 Jan 2026 15:43:25 +0000 (16:43 +0100)
committersoufiane <soufiane@cubedesigners.com>
Wed, 21 Jan 2026 15:43:25 +0000 (16:43 +0100)
js/libs/fluidbook/cart/fluidbook.cart.kimplay.js

index e76ec5199cfece45e0943f5a8495f2c6552b9c27..e18d3225ea4f72962bb2c9ddfdc4321fe0837a68 100644 (file)
@@ -4,7 +4,7 @@ function FluidbookCartKimplay(cart) {
     this.data = this.fluidbook.settings.basketReferences;
     this.showAddToCartTooltips = false;
     this.items = {};
-    this.formDataStorage = window.localStorage.getItem('formData')
+    this.formDataStorage = {};
     this.ps = null;
     this.init();
 }
@@ -13,6 +13,7 @@ FluidbookCartKimplay.prototype = {
     init: function () {
         var $this = this;
         this.items = this.fluidbook.cache.get('cart', {});
+        this.formDataStorage = this.fluidbook.cache.get('formData', {});
 
         $(document).on(this.fluidbook.input.changeEvent, '#kimplaycart input[name=qty]', function() {
             let ref = $(this).data('ref')
@@ -43,6 +44,11 @@ FluidbookCartKimplay.prototype = {
             $this.fluidbook.menu.closeView();
             $this.save();
         });
+
+        $(document).on(this.fluidbook.input.changeEvent, '#kimplay-sendcart-form input, #kimplay-sendcart-form textarea', function() {
+            $this.formDataStorage[$(this).attr('name')] = $(this).val()
+            $this.fluidbook.cache.set('formData', $this.formDataStorage);
+        })
     },
 
     emptyCart: function () {
@@ -129,15 +135,6 @@ FluidbookCartKimplay.prototype = {
         return res;
     },
 
-    setFormData: function () {
-        const form = document.getElementById("kimplay-sendcart-form");
-        if(!form) {
-            return false;
-        }
-        const formData = new FormData(form);
-        window.localStorage.setItem('formData', JSON.stringify(formData))
-    },
-
     updateCart: function () {
         if ($('#kimplaycart').length > 0) {
             $('#kimplaycart .content').html(this.getCartContent());
@@ -154,7 +151,6 @@ FluidbookCartKimplay.prototype = {
     },
 
     openCart: function (p2, callback) {
-        console.log('okkkk')
         this._endMenu(this.fluidbook.l10n.__('my selection'), this.getCartContent(), function () {
             callback();
         });
@@ -255,8 +251,8 @@ FluidbookCartKimplay.prototype = {
     },
 
     getContactForm: function() {
-        let data = JSON.parse(this.formDataStorage);
-        if(!data) {
+        let data = this.formDataStorage;
+        if(data.length > 0) {
             data = {
                 'company':'',
                 'name':'',
@@ -273,33 +269,33 @@ FluidbookCartKimplay.prototype = {
                 <form id="kimplay-sendcart-form">
                     <div class="form-group">
                         <label for="company">Nom de l'entreprise*</label>
-                        <input type="text" id="company" name="company" value="${data.company}">
+                        <input type="text" id="company" name="company" value="${data.company ?? ''}">
                     </div>
                     <br>
                     <div class="form-group">
                         <label for="name">Nom*</label>
-                        <input type="text" name="name" value="${data.name}">
+                        <input type="text" name="name" value="${data.name ?? ''}">
                     </div><br>
                     <div class="form-group">
                         <label for="firstname">Prénom</label>
-                        <input type="text" name="firstname" value="${data.firstname}">
+                        <input type="text" name="firstname" value="${data.firstname ?? ''}">
                     </div>
                     <br>
                     <div class="form-group">
                         <label for="mail">Email*</label>
-                        <input type="email" name="mail" value="${data.mail}">
+                        <input type="email" name="mail" value="${data.mail ?? ''}">
                     </div><br>
                     <div class="form-group">
                         <label for="phone">Téléphone*</label>
-                        <input type="text" name="phone" value="${data.phone}">
+                        <input type="text" name="phone" value="${data.phone ?? ''}">
                     </div><br>
                     <div class="form-group">
                         <label for="address">Adresse</label>
-                        <input type="text" name="address" value="${data.address}">
+                        <input type="text" name="address" value="${data.address ?? ''}">
                     </div><br>
                     <div class="form-group textarea">
                         <label for="message">Message</label>
-                        <textarea name="message"></textarea>
+                        <textarea name="message">${data.message ?? ''}</textarea>
                     </div><br>
                     <span>*Champs obligatoires</span>
                 </form>