简体   繁体   中英

play framework forms without helpers -not getting the errors

Im trying to generate my views without more than basic scala due to the fact that i dont know it very well.

for this reason im writing just html to make the forms the only problem i have is to get the errors that the form might have

im using on my controller:

badRequest(register.render(form));

and on my view

<label for="name">Name:</label>
    <input type="text" class="input-block-level" placeholder="Last Name" name="name">
    <dl class="input-block-level error" id="name_field">
    <dd class="error">@if(registrationForm.hasErrors) {
    @registrationForm.errors.get("name")}</dd></dl>     

this prints on the screen [ValidationError(name,error.required,[])]

i know that the helper has the '_error -> registrationForm.globalError attribute but i dont like the code generated (mainly the label)

how can i get all the error through scala?

EDIT 1: so i changed the view code to the following

 @if(registrationForm.error("name")!=null) {
    <dl class="input-block-level error" id="name_field">
    <dd class="error">
    @registrationForm.error("name").message</dd></dl>

this prints the field error but just the message key and not the message value for example error.required is printed and not the default message this field is required

Ok so i got the result i wanted in case anyone is interested in making forms without helpers

<input type="text" class="input-block-level" placeholder="Name" name="name">
    @if(registrationForm.error("name")!=null) {
    <dl class="input-block-level error" id="name_field">
    <dd class="error">
    @Messages(registrationForm.error("name").message)</dd></dl>   }  

Previous won't work since 2.1, in fact the .error(key) is an Option[FormError] so this:

@if(form.error("name")){<span class="help-inline">@Messages(form.error("name").message)</span>}

becomes:

@if(form.error("name")){<span class="help-inline">@Messages(form.error("name").get.message)</span>}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM