rvera / image-picker

Image Picker is a simple jQuery plugin that transforms a select element into a more user friendly graphical interface.
http://rvera.github.com/image-picker
Other
906 stars 216 forks source link

How to allow to retain the selection after form validations #15

Closed FrancescoMussi closed 10 years ago

FrancescoMussi commented 10 years ago

I don't know if it is a bug, or is just me that don't know how to do it. I have a form with different fields and also an Image-picker select with 5 images (with multiple selection). When there are some validation error, the message error is displayed, and the values of the other fields are filled with the pre-existing input. In Laravel4 i can do this easily with value={{ Input::old('InputName') }} but it does not work with the ImagePicker selection.

Or better, Input::old('') contains all the input from all the fields and also an array with ([0] => 'single room', [1] => 'double rooms'), that it is exactly my selection in the Image-picker select, but i don't know how to pre-select the images, according to this.

Do you understand? If you have some questions feel free to ask! Thank you for the attention!

FrancescoMussi commented 10 years ago

Hello Rvera. In this topic one guy help me to find a solution using php: http://stackoverflow.com/questions/19904984/laravel4-form-with-image-picker Is not elegant but is working. Perhaps you know how can be obtained the same goal in a more straight way? Thank you.

rvera commented 10 years ago

Hi Francesco, are you talking server side validations? If s,o you should generate the select element with the values preselected then call the plugin initialization. Since it's a server side issue there's nothing the plugin could do in this case.

FrancescoMussi commented 10 years ago

Ok, thanks. Anyway with that code from Stack Overflow i obtained what i needed. If the value of Input::old is the same value of the option value than it echo the word 'selected' inside the tag. In this way it pre-select the image. Thanks anyway for the attention!