Skip to content

Instantly share code, notes, and snippets.

@timperrett
Created May 3, 2010 11:28
Show Gist options
  • Save timperrett/387988 to your computer and use it in GitHub Desktop.
Save timperrett/387988 to your computer and use it in GitHub Desktop.
def bid(xhtml: NodeSeq): NodeSeq = {
var amountBox: Box[String] = Empty
def submit = {
for(as <- amountBox ?~ "Amount not entered";
amount <- tryo(BigDecimal(as).longValue) ?~! "Amount not a number"
) yield {
new Bid().auction(auction).customer(Customer.currentUser).amount(amount).save
}
} match {
case Full(x) => S.notice("Great, your bid was accepted!")
case Failure(msg, _, _) => S.error(msg)
case _ => S.warning("Unable to place bid at this time.")
}
SHtml.ajaxForm(bind("b",xhtml,
"amount" -%> SHtml.text(amountBox.openOr(""), s => amountBox = Full(s)) % ("id" -> "amount"),
"submit" -> SHtml.ajaxSubmit("Place Bid", () => { submit; Noop })
))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment