2

This is my view

 @helper.form(action = routes.UserController.submit(), 'class -> "form-horizontal", 'onsubmit -> "return validate();") {
    <fieldset>
        <legend>Account information</legend>


        @inputText(signupForm("firstName"),
        '_label -> "First name:",
        'class -> "form-control",
        '_help -> "Please enter your first name.",
        '_error -> signupForm.globalError
        )



        @inputText(signupForm("lastName"),
        '_label -> "Last name:",
        'class -> "form-control",
        '_help -> "Please enter your last name.",
        '_error -> signupForm.globalError

        )


        @inputText(signupForm("email"),
                    '_label -> "Email Address:",
                    'class -> "form-control",
                    '_help -> "Enter a valid email address.",
                    '_error -> signupForm.globalError)


        @inputPassword(signupForm("password"),
                        '_label -> "Password:",
                        'class -> "form-control",
                        '_help -> "A password must be at least 6 characters.")

    </fieldset>

    <div class="actions">
        <input type="submit" class="btn btn-primary" value="Sign Up">
        <a href="@routes.ApplicationController.index" class="btn">Cancel</a>
    </div>
<script type="text/javascript" charset="utf-8">
    function validate()
    {
    fname=signupForm.firstName.value;
    lname=signupForm.lastName.value;
    mail=signupForm.email.value;
    pass=signupForm.password.value;

    if( (fname.length<=0 )||(lname.length<=0)||( mail.length<=0)||(pass.length<=0) )
    {
    alert('Please fill all the fields');
    return false;
    }



    }
</script>


}

I just wants to call a javascript function onsubmit on this form Is there any way to do that? or any alternate way to call javascript function in play? i have tried this link http://www.playframework.com/documentation/2.1.1/JavaGuide6
but unable to understand it. Any help would be appreciated

1 Answer 1

2

This Scala syntax just creates HTML code, there's nothing against using JS in templates

@helper.form(action = routes.UserController.submit(), 'class -> "form-horizontal" , 'onsubmit -> "return foo();") {
    ....
} 

<script type="text/javascript" charset="utf-8">
    function foo(){
        alert("bar");
        return false;
    }
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Use browser's inspector to check if there are any errors, also examine rendered code as a standalone HTML file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.