Closed francois closed 8 years ago
Hi @francois, I'm happy that you're trying out Accord :-)
To your question, you're actually defining two separate rules: the container (i.e. Option
) must have a value, and the value itself must not be empty. One way to accomplish this (you can find additional examples in the DSL documentation):
case class SearchForm(q: Option[String])
object SearchForm {
implicit val searchFormValidator = validator[SearchForm] { form =>
form.q is notEmpty // Validates the container
form.q.each is notEmpty // Validates the value
}
}
Let me know if this works for you, or if you have some ideas on how to improve the docs.
As an aside, this makes me think that maybe additional collection-like combinators might apply (e.g. any
or once
). If this seems useful, feel free to open a feature request :-)
Wow, this page is gold! I never found it! Where is it linked from? Oh, just found it... It's the first word in the example section. I was looking for a standard navbar, either at the top or bottom of the page. Thanks for the help!
Yeah, unfortunately I've tried (and failed) a couple times to learn enough CSS to add a navbar. I guess I'll hunt down a front-end dev and sort it out :-)
PR #73 adds navigation buttons for the two pages I did not find. See them on my fork: http://francois.github.io/accord/. Cheers!
I'm in the context of a Jetty Handler. I retrieve the query parameters using
Option(request.getParameter("q"))
, and would like to validate that theq
parameter is not empty. Here's what I have coded so far:Given the above, there are three cases I'm testing for: the
q
parameter is not provided, theq
parameter is provided, but is empty, and the last case is the successful case:What I wish happened is for Accord to already have a validator for required
Option
elements. I can write my own validator that fails onNone
and runs other validations onSome
.After writing the above, I ran a test where I directly used
String
instead ofOption[String]
. This worked better, but I have the feeling this is less type-safe. The results were:Are there already Accord extensions for
Option
elements? Should I write validators forOption
values?