Răsfoiți Sursa

Change sales form 'Interested in' to be multi-select checkboxes (#8872)

* Change form helper serialization to allow for multi-values

* Change sales form 'Interested in' to be multi-select checkboxes

* Add clarification text to server pro/commons products

GitOrigin-RevId: 2732a8975ea36602375949a23b19705e4d4c9080
Thomas 4 ani în urmă
părinte
comite
79cdf5e65e

+ 7 - 1
services/web/frontend/js/features/form-helpers/hydrate-form.js

@@ -109,7 +109,13 @@ async function sendFormRequest(formEl, captchaResponse) {
   if (captchaResponse) {
     formData.set('g-recaptcha-response', captchaResponse)
   }
-  const body = Object.fromEntries(formData.entries())
+  const body = Object.fromEntries(
+    Array.from(formData.keys(), key => {
+      // forms may have multiple keys with the same name, eg: checkboxes
+      const val = formData.getAll(key)
+      return [key, val.length > 1 ? val : val.pop()]
+    })
+  )
   const url = formEl.getAttribute('action')
   return postJSON(url, { body })
 }