scala - multiple verify method on form tuple -


i'm quite new play , scala. i'm working on form , validations. couldn't figure out errors multiple verification on form.

my form tuple looks like;

val companymapping = forms.tuple(     "name" -> nonemptytext,     "email" -> email,     "password" -> nonemptytext(8),     "re-password" ->nonemptytext(8)).verifying(         // add additional constraint: both passwords must match         "passwords don't match", data => {         data._3 == data._4  }     ).verifying(         // second constraint         "test error", data => {             false  }     ) 

in view print global errors , errors, looks like;

@println(companyform.globalerror) @println(companyform.errors) 

and output;

some(formerror(,passwords don't match,wrappedarray())) list(formerror(,passwords don't match,wrappedarray()), formerror(,test error,wrappedarray())) 

at stage have absolutely no idea how print both of errors. i'm showing errors separately each input , show global errors @ end. if passwords match can see test constraint in global errors. other shows password match constraint.

here view part;

@helper.form(action = routes.login.register) {          <div class="row">             <span class="label">name</span>             <input type="text" name="name" placeholder="company name" value="@companyform("name").value" >             @if(!companyform.errors("name").isempty){                  <span class="error">@messages(companyform.errors("name")(0).message,"company name")</span>             }         </div>          <div class="row">             <span class="label">email</span>             <input type="text" name="email" placeholder="email" value="@companyform("email").value" >             @if(!companyform.errors("email").isempty){                 <span class="error">@messages(companyform.errors("email")(0).message,companyform.errors("email")(0).key)</span>             }          </div>          <div class="row">             <span class="label">password</span>             <input type="password" name="password" placeholder="password" value="@companyform("password").value" >             @if(!companyform.errors("password").isempty){                 <span class="error">@messages(companyform.errors("password")(0).message,8)</span>             }         </div>          <div class="row">             <span class="label">re-type password</span>             <input type="password" name="re-password" placeholder="re-type password" value="@companyform("re-password").value" >             @if(!companyform.errors("re-password").isempty){             <span class="error">@messages(companyform.errors("re-password")(0).message,8)</span>             }         </div>                    @println(companyform.globalerror)                    @println(companyform.errors)         <div class="row">             <span class="label"><button type="submit">save</button></span>             @companyform.globalerror.map { error =>                <span class="error">@error.message</span>             }         </div>       } 

maybe i'm confused error types. please can explain detailed.

in re-password section of template, test if !companyform.errors("re-password").isempty show message companyform.errors("re-password")(0), i.e. first error only. if have multiple errors.

you have iterate on companyform.errors("re-password") print each error.

you can example output <span class="error">... each error, using comprehension:

<div class="row">     <span class="label">re-type password</span>     <input type="password" name="re-password" placeholder="re-type password" value="@companyform("re-password").value" >     @for (error <- companyform.errors("re-password")) {     <span class="error">@messages(error.message,8)</span>     } </div> 

see play doc scala templates other useful syntax use in templates.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -