[Lift] Re: Clearing out options when submitting an empty multiSelect form

2009-09-16 Thread Derek Chen-Becker
What's happening here is that the form doesn't submit a field for beacons
at all if nothing is selected, so the callback doesn't get called. What I
typically do in scenarios like this is add a hidden field whose callback
clears the collection. In your case, you could move the
location.beacons.clear inside the hidden callback for id and have it all
taken care of.

Derek

On Wed, Sep 16, 2009 at 8:57 AM, Aaron Valade aval...@gmail.com wrote:


 Hello all-
 I'm having an issue when trying to update a many-to-one collection
 attached to a JPA object in Lift.  I'm currently using a
 SHtml.multiSelect for choosing which objects should be assigned to the
 many-to-one collection.  My bind statement looks like this:

 bind(location, xhtml,
id - SHtml.hidden(() = locationVar(current)),
name - SHtml.text(location.name, location.name = _),
beacons - SHtml.multiSelect(choices, default, {bsIds : List
 [String] = {
location.beacons.clear
bsIds.map( id =
 location.beacons.add(Model.getReference(classOf
 [Beacon], id.toLong) ) )
} } ),
save - SHtml.submit(?(Save), doAdd) )

 This works great when I'm adding or removing beacons to my location as
 long as I don't unselect all options.  When I unselect all options, my
 closure for the multiSelect doesn't get called so the beacons Set
 doesn't get cleared out.

 How can I capture when I unselect everything in my multiSelect?

 Thanks in advance!
 - Aaron

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Clearing out options when submitting an empty multiSelect form

2009-09-16 Thread Aaron Valade

On Sep 16, 2009, at 1:07 PM, Derek Chen-Becker wrote:

 What's happening here is that the form doesn't submit a field for  
 beacons at all if nothing is selected, so the callback doesn't get  
 called. What I typically do in scenarios like this is add a hidden  
 field whose callback clears the collection. In your case, you could  
 move the location.beacons.clear inside the hidden callback for  
 id and have it all taken care of.


Ah, I didn't think about adding that clear statement there.  Thanks  
Derek!

- A

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---