mcrowe / soulmate.js

A jQuery front-end for the soulmate auto-suggestion gem
MIT License
121 stars 18 forks source link

Dynamically changing types #7

Closed willcosgrove closed 12 years ago

willcosgrove commented 12 years ago

I've got a bit of an odd situation. I've got two types that I'm searching initially, but after the user selects the first item, soulmate should only search that one type. Currently, I haven't figured out a way to change the types attribute dynamically, so my first stab was to remove the input element, add it back, and reinitialize soulmate on it with the types attribute set how I needed it. But then I realized that's going to happen every time someone selects an item from soulmate.

I got around that by remembering that I can change the select callback (duh), but it would be awesome if there was just some way to change the types attribute after initialization. I don't know enough about jQuery plugins to know what the proper way to expose functionality like that would be, but I thought I'd throw this out there and see if anyone else thought it might be a useful feature.

But thank you so much @mcrowe and forkers. I know building open source stuff can be a thankless job, but thanks for building such a super awesome plugin!

mcrowe commented 12 years ago

Hi @willcosgrove . You're very welcome!

Sorry, I've had a packed week. I hope to get a chance to think about your question tomorrow, but if not, soon.

Cheers, Mitch

mcrowe commented 12 years ago

Hey @willcosgrove . Unfortunately, the way soulmate.js is designed right now, it doesn't provide any public interface. I meant to keep the plugin super simple, and didn't anticipate the need to modify the widget after initialization. That said, I did a really quick hack this morning and think that I've got a version that would do what you'd like. Check out this branch:

https://github.com/mcrowe/soulmate.js/tree/setting-type-after-initialization

If you use the src/compiled/jquery.soulmate.js from that branch, you should now get the an object returned when you initialize the autocompleter that you can call setTypes on with an array. I didn't have time to test this, so it may have a typo or two. If so, check out the diff in `src/jquery.soulmate.coffee to see what I've changed, and it should be pretty clear what I was going for if you want to tweak it yourself.

I wouldn't want to pull this into master as is, 'cause there are no tests, and it exposes a bunch of other methods that should be private, but I really hope that it works for you. I'm off for two-weeks' vacation this w/e, so best of luck to you in the meantime!

mcrowe commented 12 years ago

Sorry, just looked at the diff and realized I commited a bunch of whitespace changes which make it tougher to see what I've done. Just focus on lines 270 on if you're checking it out.

mcrowe commented 12 years ago

I'm going to mark this resolved for the time being. Feel free to re-open it later if you'd like.

willcosgrove commented 12 years ago

Awesome, thanks so much!