Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Form with a char type (Radio Button howto)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Christian Espinoza  
View profile  
 More options Oct 24 2012, 12:00 pm
From: Christian Espinoza <chespin...@gmail.com>
Date: Wed, 24 Oct 2012 09:00:33 -0700 (PDT)
Local: Wed, Oct 24 2012 12:00 pm
Subject: [2.0-scala] Form with a char type (Radio Button howto)

Hello, I'm newbie with playand  I'm try to render this Form:

Model:
case class Service (
name: String, description: String, unitcost: Long, typo: Char, isactive:
Char, modifiedby: String)

Controller:

private val servicesForm[Service] = Form(
mapping(
"name" -> nonEmptyText.verifying(
"validation.name.duplicate", Service.findByName(_).isEmpty),
"description" -> nonEmptyText,
"unitcost" -> longNumber,
"typo" -> of[Char],
"isactive" -> of[Char],
"modifiedby" -> nonEmptyText
) (Service.apply)(Service.unapply)
)

But I get this Error: Cannot find Formatter type class for Char. Perhaps
you will need to import play.api.data.format.Formats._

Both vars are Char type that I need fill each one with a char value like
'Y' or 'N', for this I want a radio button pair for each selection
but I don't know how to do that...

I can't find samples to guide me with this..

PD: I had imported play.api.data.format.Formats._

Thanks in Advance.
Christian.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Roper  
View profile  
 More options Oct 25 2012, 8:08 pm
From: James Roper <jrop...@gmail.com>
Date: Thu, 25 Oct 2012 17:08:04 -0700 (PDT)
Local: Thurs, Oct 25 2012 8:08 pm
Subject: Re: [2.0-scala] Form with a char type (Radio Button howto)

The Forms API uses implicit conversions to convert form values into
whatever you need, and we haven't yet implemented one for converting to
Char.  However, you can implement your own, eg:

  implicit def charFormat: Formatter[Char] = new Formatter[Char] {

    override val format = Some(("format.char", Nil))

    def bind(key: String, data: Map[String, String]) =
      parsing(_.head, "error.char", Nil)(key, data)

    def unbind(key: String, value: Char) = Map(key -> value.toString)
  }

Note that the error.char and format.char keys above you'll have to define
in your messages file.

Though, if you're expecting just values of Y or N, why not treat it as a
Boolean?  Then you could do something like this:

  val ynFormat = new Formatter[Boolean] {

    override val format = Some(("format.yn", Nil))

    def bind(key: String, data: Map[String, String]) = {
      Right(data.get(key).getOrElse("N")).right.flatMap {
        case "Y" => Right(true)
        case "N" => Right(false)
        case _ => Left(Seq(FormError(key, "error.yn", Nil)))
      }
    }

    def unbind(key: String, value: Boolean) = Map(key -> value match {
      case true -> "Y"
      case false -> "N"
    })
  }

and in your form:

      typo -> of(ynFormat)
      isActive -> of (ynFormat)

Even simpler would be rather than use Y and N, use true and false, and then
just declare to be of[Boolean], and everything will just work.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Espinoza  
View profile  
 More options Oct 26 2012, 11:24 am
From: Christian Espinoza <chespin...@gmail.com>
Date: Fri, 26 Oct 2012 08:24:15 -0700 (PDT)
Local: Fri, Oct 26 2012 11:24 am
Subject: Re: [2.0-scala] Form with a char type (Radio Button howto)

Thanks James, keeping on mind your tips, I'm thinking should be more easy
to use these vars like Boolean types and on the model translate it to chars
in order to adjust it to my Database schema...

Thanks.

PD: To work with datetime stamps from the database, then I should use it
like a string and parse any format that I'll need??

Regards.
Christian.

El jueves, 25 de octubre de 2012 21:08:04 UTC-3, James Roper escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »