scala - Play Framework Form Error Handling -


this view file containing form has filled in user:

@helper.form(call) {     @helper.input(resumeform("surname"), '_label -> "surname") { (id, name, value, args) =>         <input name="@name" type="text" value="@value" placeholder="enter surname">     } } 

this custom field constructor:

@(elements: helper.fieldelements)  @if(!elements.args.isdefinedat('showlabel) || elements.args('showlabel) == true) {     <div class="input-with-label text-left">         <span>@elements.label</span>         @elements.input     </div> } else {     @elements.input } 

now have dilemma. when entered value doesn't clear validation, need add class field-error input , need add data-toggle, data-placement , title. however, don't know of way check if there errors specific field. best way implement this? looked @ using inputtext or same base input not have access errors. i'm unable alter html of elements.input inside field constructor.

have @ play documentation: writing own field constructor. can check on errors @if(elements.haserrors) within template of custom field constructor.

<div class="input-with-label text-left @if(elements.haserrors){field-error}">     ... 

edit:

you can pass error state of field via args parameter input. play docs:

note: parameters added generated html, except ones name starts _ character. arguments starting underscore reserved field constructor argument (which see later).

you need cast matching type though.

@input(resumeform("surname"), '_label -> "surname", 'haserrors -> resumeform("surname").haserrors) { (id, name, value, args) =>     <input name="@name" type="text" value="@value" placeholder="enter surname"         class="@if(args.get('haserrors).map(_ match { case x:boolean => x}).get){field-error}"> } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -