Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9030479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:30:06+00:00 2026-06-16T07:30:06+00:00

How can I show a validation error for a form field outside of a

  • 0

How can I show a validation error for a form field outside of a field constructor in Play framework 2? Here is what I tried:

@eventForm.("name").error.message

And I get this error:

value message is not a member of Option[play.api.data.FormError]

I’m confused because in the api docs it says message is a member of FormError. Also this works fine for global errors:

@eventForm.globalError.message
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:30:07+00:00Added an answer on June 16, 2026 at 7:30 am

    You can get a better grasp of it checking Form’s sourcecode here

    Form defines an apply method:

     def apply(key: String): Field = Field(
        this,
        key,
        constraints.get(key).getOrElse(Nil),
        formats.get(key),
        errors.collect { case e if e.key == key => e },
        data.get(key))
    

    That, as said in the doc, returns any field, even if it doesn’t exist. And a Field has an errors member which returns a Seq[FormError]:

    So, you could do something like that (for the Seq[FormError]):

    eventForm("name").errors.foreach { error =>
      <div>@error.message</div>
    }
    

    Or (for the Option[FormError])

    eventForm("name").error.map { error =>
      <div>@error.message</div>
    }
    

    Or, you could use Form errors:

      def errors(key: String): Seq[FormError] = errors.filter(_.key == key)
    

    And get all errors of a given key. Like this (for the Seq[FormError]):

    eventForm.errors("name").foreach { error =>
          <div>@error.message</div>
    }
    

    Or (for the Option[FormError])

    eventForm.error("name").map { error =>
              <div>@error.message</div>
    }
    

    If you want more details, check the source code. It’s well written and well commented.

    Cheers!

    EDIT:

    As biesior commented: to show human readable pretty messages with different languages you have to check how play works I18N out here

    To be thorough you’re probably going to have to deal with I18N. It’s not hard at all to get it all working.
    After reading the documentation you may still find yourself a bit consufed. I’ll give you a little push. Add a messages file to your conf folder and you can copy its content from here. That way you’ll have more control over the default messages. Now, in your view, you should be able to do something like that:

    eventForm.errors("name").foreach { error =>
              <div>@Messages(error.message, error.args: _*)</div>
    }
    

    For instance, if error.message were error.invalid it would show the message previously defined in the conf/messages file Invalid value. args define some arguments that your error message may handle. For instance, if you were handling an error.min, an arg could be the minimum value required. In your message you just have to follow the {n} pattern, where n is the order of your argument.

    Of course, you’re able to define your own messages like that:

    error.futureBirthday=Are you sure you're born in the future? Oowww hay, we got ourselves a time traveler!
    

    And in your controller you could check your form like that (just one line of code to show you the feeling of it)

    "year" -> number.verifying("error.furtureBirthday", number <= 2012) // 2012 being the current year
    

    If you want to play around with languages, just follow the documentation.

    Cheers, again!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can we show error message on form validation on joomla 2.5 in the
How can i display the validation error messages just below the form field rather
How i can show a close button after certain elapsed, i tried settimeout but
I've got a wpf form where validation works fine for single-field validation. I've got
Im breaking my head here. Hope you can see what's the error. I've installed
Can I display a single message for the multiple form fields in CodeIgniter? For
So I have a form with both javascript validation to check each field is
I still struggle with the form validation and form helpers in Play 2.0. I
I tried to submit a new post and I get the error Title can't
can anyone recommend a website crawler that can show me all of the links

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.