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

Reset selected value on external value update? #61

Closed moens closed 9 years ago

moens commented 9 years ago

(tl;dr) My js is weak... How should I trigger image-picker to update the selected value from external js?

I have a form which is populated with values from an existing model. If the user feels they have screwed up the form, a button allows them to reset original model values. The image picker js is not triggered, so even though the form value for a select is reset, image-picker is not aware of the select value update, and the form select presentation is incorrect. TIA

SgtOddball commented 9 years ago

Easy, just trigger the following once the select value has changed.

this.data('picker').sync_picker_with_select();

Just remember to replace this with the element the image picker is assigned to (the select dropdown object). So long as something triggers the sync check, it'll change the image picker accordingly (I use this to great effect with a select all button).

rvera commented 9 years ago

Exactly what @SgtOddball said. Thanks for taking the time to answer this.

moens commented 9 years ago

Thanks, just what I needed... but in the future I expect faster turn-around on answers to these issues... jk ;) you guys are freaking awesome.

@rvera, thanks for the image-picker. Point me to a paypal donate button or something. I'll buy you a beer or two.

rvera commented 9 years ago

Haha, thanks @moens but it's not necessary. Maybe @SgtOddball would take you up on that offer?

I'm glad you find it useful.

moens commented 9 years ago

meh... ok, someone should benefit (not just me)!

SgtOddball commented 9 years ago

I've got enough beer kicking around and besides, @rvera did the main work. I just happened to have the code to hand.

moens commented 9 years ago

Well, thanks all!