Ok, I was actually over-complicating things a bit as I had not set up my associations properly.. So, the tag is now reduced to pretty much just adding a "param-name" attribute, which sets the name attribute for each item instead of using param_name_for_this - that method was not returning anything, I think because it is outside the 'this' context, a many-to-many relationship.
The other problem is, that on the hobo_update side it is not automagically making objects for the ID's passed in, I guess also because of the many-to-many thing. So I have a load of custom code extracting the hash out of the params and saving/deleting as necessary. I admit I was getting a bit baffled trying to work out how hobo does all that stuff... On Jun 24, 10:22 pm, Bryan Larsen <[email protected]> wrote: > I haven't worked through your code to closely, but it looks to me like > you've mainly just added features to select-many. Is it usable for > other people -- should it be added to Rapid? Can you update the > documentation too? > > thanks, > Bryan > > adamski wrote: > > OK - problem solved... if anyone is interested, my custom tag looks > > like so: > > > p.s. it does not yet disable the already chosen values on page load. > > > <def tag="select-many-custom" attrs="options, targets, param-name, > > field-name, remove-label, prompt, disabled"><% > > prompt ||= "Add #{this_field.titleize.singularize}" > > options ||= this_field_reflection.klass.all(:conditions > > =>this.conditions).select {|x| can_view?(x)} > > field_name ||= 'id' #allow user to change field for > > outputting values (.e.g 'user_id' ) > > values = this > > > @param_name ||= param_name_for_this > > > -%> > > <div class="input select-many" merge-attrs> > > <div style="display:none" class="item-proto"> > > <div class="item" param="proto-item"> > > <span></span> > > <input type="hidden" name="#{param_name}[]" param="proto- > > hidden"/> > > <input type="button" class="remove-item" value="#{remove_label > > || 'Remove'}" param="proto-remove-button"/> > > </div> > > </div> > > <div class="items"> > > <set param-name="¶m_name_for_this"/> > > <div class="item" param="item" repeat> > > <span><%= h this.to_s %></span> > > <input type="hidden" name="#...@param_name}[]" value="@#{h > > this.send(field_name)}" disabled="&disabled" > > param="hidden"/> > > <input type="button" class="remove-item" value="#{remove_label > > || 'Remove'}" disabled="&disabled" > > param="remove-button"/> > > </div> > > </div> > > <select merge-attrs="&{:disabled => disabled}"> > > <option value=""><prompt/></option> > > <option repeat="&options.sort_by {|x| x.to_s.downcase}" value="@# > > {this.id}" > > merge-attrs="&{:disabled => 'true'} if (this.in?(values) > > || this.to_s.in?(values))"><%= h this.to_s %></option> > > </select> > > </div> > > </def> > > > On Jun 23, 5:48 pm, adamski <[email protected]> wrote: > >> I"m trying to make a custom select-many based on Hobo's rapid tag. > >> This is mainly because the relationship I need it for is polymorphic > >> and does not seem to work with the tag as it is. > > >> The main prob is: I dont get how removing things works? > >> Is hobo_update comparing the list with whats in the database to work > >> out what to delete? I suspect there is a simple elegant solution here > >> that I am not seeing. > > >> Any info much appreciated ! > > >> Thx --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/hobousers?hl=en -~----------~----~----~----~------~----~------~--~---
