I have the use case of being able to select one or more values from a mulitiselect
So, far this is the code I have come up with: This code is able to display the multiset.
The User is able to select items from the set of all items that make up the multiselect combo.
The goal:
I am looking to add the ability to Edit a selection (a name) if desired. Once the selection is edited, the item now
assumes the new value and the multiselect is modified accordingly.
I would also like to be able to delete an item at will, but for now, ability to change or edit an item would be
what I want to achieve.
Please tell me what can be done with this code, when you are able to get to it.
Thanks for everybody's time.
def modifyNames(populationRegistry: populationClass[T]) = {
val blankOption = Seq[(String, String)](("",""))(0)
val default = Seq("") // the default argument in the multiselect method
//allNames is pulled from a database, added to a so-called blankOption (for the first blank item) and this
//represents the initial items in the multiselect
val nameOpt = blankOption +: allNames.sortWith( (e1, e2) => (e1 compareToIgnoreCase e2) < 0 ).map{s:String => (s,s)}
var existingNames = populationRegistry.getTags
var newName = false
var newNameValue = "" //a new name can be added to the currently available version of the multiselect. This is a user entry via a checkbox and a textbox
//Yes, Add ability exists, but I would like to Edit and Delete also, Edit is a first step.
// a Set of all multiselect Name elements that represents any combination of items selected from nameOpt; this is done via an Add and displayed in a table.
//This operation is available to each individual row in a table, representing some Entity, which we shall a Entry
//the nameSet at any moment is the number of those selections in the multiselect
var nameSet:Set[String] = if (existingNames.contains("None")) Set.empty else existingNames.toSet
val nodeSeq = Text("Please select one or more names:") ++
<div>{SHtml.multiSelect(nameOpt, existingNames, existingNames = _, ("size" -> math.min(20, nameOpt.size).toString), ("style" -> "min-width:200px"))}</div> ++
<div>
<span>{SHtml.checkbox(false,newName = _)}</span><span> New Name:</span>
<span>{SHtml.ajaxText(newNameValue,newNameValue = _)}</span>
</div>
val func = () => {
if (newName) {
logger.info("func - 2: create a new name")
logger.info("func - 2: newNameValue is: " + newNameValue)
nameSet = nameSet + newNameValue
logger.info("func - 2:updated nameSet is: " + nameSet)
populationRegistry.setTags(existingNames.toSet)
allNames.prepend(newNameValue)
} else {
populationRegistry.setTags(nameSet)
}
renderJsCmd
}
//in this popup we display the multiselect; User does a single select or multiselect, and
//performs Add.
showFormPopup(nodeSeq, func,"Select Names")
}