wpmetabox / meta-box

The best plugin for WordPress custom fields and custom meta boxes
https://metabox.io
1.19k stars 423 forks source link

fix: cannot save first value of autocomplete #1550

Closed tanftw closed 9 months ago

tanftw commented 9 months ago

This issue is related to JQuery UI treating the first element of array differently.

we have an array like:

['Foo', 'Bar', 'Baz']

If we select 'Bar' or 'Baz', ui.item.value returns 1 or 2, but if we select 'Foo', it returns its label instead of actual value, in this case, it returns 'Foo' instead of 0. So, the value returned is wrong.

rilwis commented 9 months ago

A nghĩ khả năng cao là do <input> ẩn ở dòng 53 này

https://github.com/wpmetabox/meta-box/pull/1550/files#diff-35286fdb484a24c89570c7aa3a9cd7a7f4e6793240e01ead2c8c8f509b39f102R53

Nên khi submit, tự nhiên sẽ có thêm 1 giá trị ở đầu. E check lại xem có đúng ko nhé.

Còn phần fix của e thì cũng ko có hại gì :)

tanftw commented 9 months ago

Nên khi submit, tự nhiên sẽ có thêm 1 giá trị ở đầu. E check lại xem có đúng ko nhé.

Không phải đâu a, cái input đó disabled rồi nên value sẽ không submit nữa.

Field này mỗi lần user click vào dropdown sẽ tạo 1 hidden field và lưu giá trị của ui.item.value vào đó chờ submit:

https://i.imgur.com/6pmL8LA.png

Đây là console.log của cái ui.item.value

https://i.imgur.com/sT4rRpV.png