Created
November 3, 2012 13:36
-
-
Save tgpfeiffer/4007403 to your computer and use it in GitHub Desktop.
Lift: CRUD interface for "foreign keys" using a multiselect and select2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
object author extends ObjectIdRefListField(this, MongoTerm) | |
with One2ManyCRUD[BsonMetadata, MongoTerm] { | |
override def options = MongoTerm.findAll(("category" -> "person")).map(x => (x.id.is, x.title)) | |
} | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="lift:surround?with=default;at=content"> | |
<div class="page-header"> | |
<h1 class="lift:Loc.i">Content</h1> | |
</div> | |
<div class="lift:EditPage"> | |
<form method="post"> | |
<select multiple="multiple"> | |
<option>...</option> | |
</select> | |
<input type="submit" value="Save" /> | |
</form> | |
</div> | |
<script type="text/javascript"> | |
$("select").select2({ | |
width : "element" | |
}); | |
</script> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This trait provides display and edit interfaces for one2many fields and | |
* is to be mixed in to a ObjectIdRefListField. Edit will be done using a | |
* multiselect widget. | |
*/ | |
trait One2ManyCRUD[A <: BsonRecord[A], B <: MongoRecord[B]] | |
extends ObjectIdRefListField[A, B] { | |
override def toForm = { | |
Full(SHtml.multiSelectObj(options, is, set)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment