preline icon indicating copy to clipboard operation
preline copied to clipboard

AdvancedSelect is not submitted in the form data

Open bekaddourelhadjali opened this issue 1 year ago • 4 comments

Summary

AdvancedSelect is not submitted in the form data

Steps to Reproduce

I'm using laravel with vite and i added preline package but it's not submitting the select in the form should i create a hidden input and implement on change function so it can put the values in the hidden input ?

`

                <div class="flex gap-4 flex-col sm:flex-row">
                    <h1 class="block antialiased tracking-normal font-sans font-semibold text-blue-gray-900 !leading-snug lg:!text-3xl !text-2xl max-w-2xl">Add New Lease</h1>
                    <button type="submit" class="inline-block align-middle text-center select-none border font-normal whitespace-no-wrap rounded-full py-1 px-6 leading-normal no-underline bg-blue-800 text-white hover:bg-blue-800">Save Property</button>
                </div>
                @csrf
                <div class=" p-4 px-4 md:p-8 mb-6">
                    <div class="grid gap-4 gap-y-2 text-sm grid-cols-1 md:grid-cols-4">
                        <div class="md:col-span-2">
                            <label for="property_id" class="block mb-2 font-sans text-sm antialiased font-medium leading-normal text-blue-gray-900">
                                Property
                            </label>
                            <div class="relative h-10 w-full">
                                <!-- Select -->
                                <select name="property_id" multiple="" :hasSearch data-hs-select='{
                                          "placeholder": "Select property...",
                                          "toggleTag": "<button type=\"button\"></button>",
                                          "toggleClasses": "hs-select-disabled:pointer-events-none hs-select-disabled:opacity-50 relative flex text-nowrap w-full cursor-pointer bg-white border border-gray-200 rounded-lg text-start text-sm focus:border-blue-500 focus:ring-blue-500",
                                          "dropdownClasses": "mt-2 z-50 w-full max-h-72 p-1 space-y-0.5 bg-white border border-gray-200 rounded-lg overflow-hidden overflow-y-auto [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-track]:bg-gray-100 [&::-webkit-scrollbar-thumb]:bg-gray-300",
                                          "optionClasses": "py-2 px-4 w-full text-sm text-gray-800 cursor-pointer hover:bg-gray-100 rounded-lg focus:outline-none focus:bg-gray-100",
                                          "mode": "tags",
                                          "wrapperClasses": "relative ps-0.5 pe-9 min-h-[46px] flex items-center flex-wrap text-nowrap w-full border border-gray-200 rounded-lg text-start text-sm focus:border-blue-500 focus:ring-blue-500",
                                          "tagsItemTemplate": "<div class=\"flex flex-nowrap items-center relative z-10 bg-white border border-gray-200 rounded-full p-1 m-1\"><div class=\"size-6 me-1\" data-icon></div><div class=\"whitespace-nowrap text-gray-800\" data-title></div><div class=\"inline-flex flex-shrink-0 justify-center items-center size-5 ms-2 rounded-full text-gray-800 bg-gray-200 hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-gray-400 text-sm cursor-pointer\" data-remove><svg class=\"flex-shrink-0 size-3\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M18 6 6 18\"/><path d=\"m6 6 12 12\"/></svg></div></div>",
                                          "tagsInputClasses": "py-3 px-2 rounded-lg order-1 text-sm outline-none",
                                          "optionTemplate": "<div class=\"flex items-center\"><div class=\"size-8 me-2\" data-icon></div><div><div class=\"text-sm font-semibold text-gray-800\" data-title></div><div class=\"text-xs text-gray-500\" data-description></div></div><div class=\"ms-auto\"><span class=\"hidden hs-selected:block\"><svg class=\"flex-shrink-0 size-4 text-blue-600\" xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" fill=\"currentColor\" viewBox=\"0 0 16 16\"><path d=\"M12.736 3.97a.733.733 0 0 1 1.047 0c.286.289.29.756.01 1.05L7.88 12.01a.733.733 0 0 1-1.065.02L3.217 8.384a.757.757 0 0 1 0-1.06.733.733 0 0 1 1.047 0l3.052 3.093 5.4-6.425a.247.247 0 0 1 .02-.022Z\"/></svg></span></div></div>",
                                          "extraMarkup": "<div class=\"absolute top-1/2 end-3 -translate-y-1/2\"><svg class=\"flex-shrink-0 size-3.5 text-gray-500\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"m7 15 5 5 5-5\"/><path d=\"m7 9 5-5 5 5\"/></svg></div>"
                                        }' class="hidden">
                                    <option value="">Choose</option>
                                    @foreach($properties as $property)
                                        <option value="{{$property->property_id}}" data-hs-select-option='{
                                              "description": "{{$property->name}}",
                                              "icon": "<img class=\"inline-block rounded-full h-full\" src=\"{{$property->getPhotoUrl()}}\" />"
                                            }'>{{$property->name}}</option>
                                    @endforeach
                                </select>
                                <!-- End Select -->
                            </div>
                        </div>`

Demo Link

https://preline.co/plugins/html/advanced-select.html

Expected Behavior

I expect the select to be sent with the form

Actual Behavior

It works fine but it's not sending the select in the request

Screenshots

No response

bekaddourelhadjali avatar Jun 26 '24 14:06 bekaddourelhadjali

and if someone also has a solution for this

the multiselect is working but when i remove an option the onchange event doesn't trigger

bekaddourelhadjali avatar Jun 27 '24 20:06 bekaddourelhadjali

I encountered the same issue. Adding/Removing tags should update the native select tag options.

abdelbk avatar Sep 21 '24 21:09 abdelbk

@bekaddourelhadjali Hi, I tested the form, it looks fine, at least the FormData object stores the selected values.

My test JS code:

(function() {
  const testForm = document.querySelector("#test-form");
  const {element} = HSSelect.getInstance("#test", true);

  element.el.addEventListener("change", () => {
    const formData = new FormData(testForm);

    for (let [name, value] of formData.entries()) {
      console.log(name, value);
    }
  });
})();

My test HTML:

<form id="test-form">
  <!-- Select -->
  <label class="hidden" for="hs-tags-input">Tags label</label>
  <select id="test" name="tags" multiple data-hs-select='{
    "placeholder": "Select option...",
    "dropdownClasses": "mt-2 z-50 w-full max-h-72 p-1 space-y-0.5 bg-white border border-gray-200 rounded-lg overflow-hidden overflow-y-auto [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-track]:bg-gray-100 [&::-webkit-scrollbar-thumb]:bg-gray-300 dark:[&::-webkit-scrollbar-track]:bg-neutral-700 dark:[&::-webkit-scrollbar-thumb]:bg-neutral-500 dark:bg-neutral-900 dark:border-neutral-700",
    "optionClasses": "py-2 px-4 w-full text-sm text-gray-800 cursor-pointer hover:bg-gray-100 rounded-lg focus:outline-none focus:bg-gray-100 hs-select-disabled:pointer-events-none hs-select-disabled:opacity-50 dark:bg-neutral-900 dark:hover:bg-neutral-800 dark:text-neutral-200 dark:focus:bg-neutral-800",
    "mode": "tags",
    "wrapperClasses": "relative ps-0.5 pe-9 min-h-[46px] flex items-center flex-wrap text-nowrap w-full border border-gray-200 rounded-lg text-start text-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-neutral-900 dark:border-neutral-700 dark:text-neutral-400",
    "tagsItemTemplate": "<div class=\"flex flex-nowrap items-center relative z-10 bg-white border border-gray-200 rounded-full p-1 m-1 dark:bg-neutral-900 dark:border-neutral-700 \"><div class=\"size-6 me-1\" data-icon></div><div class=\"whitespace-nowrap text-gray-800 dark:text-neutral-200 \" data-title></div><div class=\"inline-flex shrink-0 justify-center items-center size-5 ms-2 rounded-full text-gray-800 bg-gray-200 hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-gray-400 text-sm dark:bg-neutral-700/50 dark:hover:bg-neutral-700 dark:text-neutral-400 cursor-pointer\" data-remove><svg class=\"shrink-0 size-3\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M18 6 6 18\"/><path d=\"m6 6 12 12\"/></svg></div></div>",
    "tagsInputId": "hs-tags-input",
    "tagsInputClasses": "py-3 px-2 rounded-lg order-1 text-sm outline-none dark:bg-neutral-900 dark:placeholder-neutral-500 dark:text-neutral-400",
    "optionTemplate": "<div class=\"flex items-center\"><div class=\"size-8 me-2\" data-icon></div><div><div class=\"text-sm font-semibold text-gray-800 dark:text-neutral-200 \" data-title></div><div class=\"text-xs text-gray-500 dark:text-neutral-500 \" data-description></div></div><div class=\"ms-auto\"><span class=\"hidden hs-selected:block\"><svg class=\"shrink-0 size-4 text-blue-600\" xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" fill=\"currentColor\" viewBox=\"0 0 16 16\"><path d=\"M12.736 3.97a.733.733 0 0 1 1.047 0c.286.289.29.756.01 1.05L7.88 12.01a.733.733 0 0 1-1.065.02L3.217 8.384a.757.757 0 0 1 0-1.06.733.733 0 0 1 1.047 0l3.052 3.093 5.4-6.425a.247.247 0 0 1 .02-.022Z\"/></svg></span></div></div>",
    "extraMarkup": "<div class=\"absolute top-1/2 end-3 -translate-y-1/2\"><svg class=\"shrink-0 size-3.5 text-gray-500 dark:text-neutral-500 \" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"m7 15 5 5 5-5\"/><path d=\"m7 9 5-5 5 5\"/></svg></div>"
  }' class="hidden">
    <option value="">Choose</option>
    <option selected value="1" data-hs-select-option='{
        "description": "chris",
        "icon": "<img class=\"inline-block rounded-full\" src=\"https://images.unsplash.com/photo-1531927557220-a9e23c1e4794?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=facearea&facepad=2&w=300&h=300&q=80\" />"
      }'>Christina</option>
    <option value="2" data-hs-select-option='{
        "description": "david",
        "icon": "<img class=\"inline-block rounded-full\" src=\"https://images.unsplash.com/photo-1568602471122-7832951cc4c5?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=facearea&facepad=2&w=300&h=300&q=80\" />"
      }'>David</option>
    <option value="3" disabled data-hs-select-option='{
        "description": "alex27",
        "icon": "<img class=\"inline-block rounded-full\" src=\"https://images.unsplash.com/photo-1492562080023-ab3db95bfbce?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=facearea&facepad=2&w=300&h=300&q=80\" />"
      }'>Alex</option>
    <option value="4" data-hs-select-option='{
        "description": "samia_samia",
        "icon": "<img class=\"inline-block rounded-full\" src=\"https://images.unsplash.com/photo-1541101767792-f9b2b1c4f127?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=facearea&facepad=2&w=300&h=300&q=80\" />"
      }'>Samia</option>
  </select>
  <select name="tags2" multiple>
    <option value="1" selected>Christina</option>
    <option value="2" selected>David</option>
    <option value="3" selected>Alex</option>
    <option value="4" selected>Samia</option>
  </select>
  <!-- End Select -->
</form>
_01

olegpix avatar Oct 07 '24 14:10 olegpix

@bekaddourelhadjali @abdelbk You're right, guys, the trigger doesn't work when deleting. We'll fix this in the next update.

olegpix avatar Oct 07 '24 14:10 olegpix

Hey everyone, the issue has been fixed with the latest v2.6.0 release. Thanks!

jahaganiev avatar Dec 04 '24 00:12 jahaganiev