1

I want to implement some simple form validation in my AngularJS app, but I don't want it to show any validation errors until after the user has clicked the form submit button. I don't want it to validate as I type or even on exiting the field.

Is there a way to do this? I'll need to write at least one custom validator directive so it will need to work with that.

I am finding form validation in AngularJS to be very difficult so far, it's hard to get it to work exactly as you want.

1 Answer 1

1

You could do something like this. Here's an example

<form name="form" ng-app>
    <div class="control-group" ng-class="{true: 'error'}[submitted && form.email.$invalid]">
            <label class="control-label" for="email">Your email address</label>
            <div class="controls">
                <input type="email" name="email" ng-model="email" required />
                <span class="help-inline" ng-show="submitted && form.email.$error.required">Required</span>
                <span class="help-inline" ng-show="submitted && form.email.$error.email">Invalid email</span>
            </div>
        </div>

        <button type="submit" class="btn btn-primary btn-large" ng-click="submitted=true">Submit</button>
    </form>
Sign up to request clarification or add additional context in comments.

1 Comment

You could use this as a reference and should change according to your needs.

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.