rawilk / laravel-form-components

Form components built for Tailwind & Livewire.
https://randallwilk.dev/docs/laravel-form-components
MIT License
394 stars 44 forks source link

Custom select breaks when value is get from old and is an integer #40

Closed luilliarcec closed 2 years ago

luilliarcec commented 3 years ago

Laravel Form Components Version

v6.0.0

Laravel Version

v8.63.0

Alpine Version

v3.4.2

Bug description

When using the component outside of Livewire, the component breaks if the selected value is an integer but only when it is obtained from old, this happens because the value returned by old is transformed to a string. For example select Apple with key 1 when old returns it to me is "1".

image

image

As I mention. this happens after submitting and receiving the value of old.

I investigated the source code and the selectedKey property returns the correct array, however, this seems to be one more JS error due to the triple comparison that exists in the following lines of code.

custom-select.js#L185

custom-select.js#L187

However, it is a somewhat vague assessment, I have not tested it to be true, if changing said comparison solves the problem.

Steps to reproduce

Model::create([
  'id' => 1,
  'name' => 'Laravel'
]);

$data = Model::get(['id', 'name']);
<x-custom-select
    :options="$data"
    value-field="id"
    text-field="name"
    name="model_name_input"
    filterable
    multiple
    optional
/>

Relevant log output

No response

luilliarcec commented 3 years ago

Maybe I can assure that the problem is the triple JS comparison ... I tried casting my Id to string and it really worked.

image

image

image

rawilk commented 2 years ago

I'll be revamping the custom select component in a major release I'm working on right now, so hopefully this kind of issue will be addressed when I get the chance to work on it.

rawilk commented 2 years ago

In the upcoming v7 release of this package, this shouldn't be an issue anymore with this component. I'm closing for now but feel free to re-open if it is still an issue in v7.