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

  • SEARCH
  • Home
  • 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 7691019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:31:46+00:00 2026-05-31T20:31:46+00:00

In this question: If a form field has multi validators, how to let play

  • 0

In this question: If a form field has multi validators, how to let play verify them one by one, not all?, Julien gave me a method named stopOnFirstFail to solve my problem:

def stopOnFirstFail[T](constraints: Constraint[T]*) = Constraint { field: T =>
  constraints.toList dropWhile (_(field) == Valid) match {
    case Nil => Valid
    case constraint :: _ => constraint(field)
  }
}

It’s usage is:

val loginForm = Form(
  "name" -> (text verifying stopOnFirstFail( nonEmpty, minLength(4) ))
)

But I hope to define a dsl which can be used as:

val loginForm = Form(
  "name" -> (text verifying ( nonEmpty or minLength(4) ))
)

I tried to defined an implicit method for play.api.data.validation.Constraint:

import play.api.data.validation._

implicit def _Constraint[T](cons: Constraint[T]) = new {

  def or[T](other: Constraint[T]) = Constraint { field: T =>
    cons(field) match {              // (!)
      case Valid => other(field)
      case invalid => invlaid
    }
  }
}

But it can’t be compiled, the error in on the (!) line, and message is:

type mismatch; 
found: field.type (with underlying type T) required: T 
Note: implicit method _Constraint is not applicable here
      because it comes after the application point and it lacks an explicit result type

How to fix it?

  • 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-05-31T20:31:48+00:00Added an answer on May 31, 2026 at 8:31 pm

    The or method does not take a type parameter:

    implicit def toLazyOr[T](cons: Constraint[T]) = new {
      def or(other: Constraint[T]) = Constraint { field: T =>
        cons(field) match {
          case Valid => other(field)
          case Invalid => Invalid
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question has been asked here in one form or another but not quite
I have a follow-up question to this one . I created a new form,
This is probably a basic html/css question... I have a simple one-button form that
First off, let me start by saying, I know this exact question has been
This question involves 3 tables and 1 form in my Access database. The tables
The short form of this question: When, if ever, is it appropriate to use
In this question I asked how to POST to a php file form a
I have this question relating to Lucene. I have a form and I get
Referring to this question: https://stackoverflow.com/questions/2035449/why-is-oop-hard-for-me class Form { protected $inputs = array(); public function
this is a simple question. I have a form that is being validated using

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.