Reputation: 1211
how to prevent the auto validation on a form? Everytime I load the template with the form, it automatically validates itself even without any data typed in to the inputs.
I want to trigger the validation on submit.
HTML:
<span ng-show='message.$invalid == true'>This e-mail is black-listed!</span>
<form novalidate class="dealermessageform" name="message">
<input type="text" name="messagename" placeholder="Name" class="messagename" ng-model="user.name" required>
<input type="email" name="messageemail" placeholder="E-Mail Adresse*" class="messageemail" ng-model="user.email" required>
<textarea class="message" name="message" placeholder="Schreibe eine Nachricht. *" required></textarea>
<span class="help-block">*alle markierten Felder sind Pflichtfelder</span>
<div class="grid_4 alpha omega submitbutton">
<input type="submit" class="submitbutton" value="Senden" id="submit" ng-click="send()">
</div>
</form>
And how is it possible, to show the "span" field above the form, ONLY if some errors are TRUE after submit?
It also directly shows up when I enter the form.
Upvotes: 2
Views: 3910
Reputation: 35829
It shouldn't be a problem if validation already occurs. You just shouldn't show the error message. You can do that with $pristine or $dirty, depending if you use ng-show
or ng-hide
:
<span class="help-block" ng-show="message.$dirty && message.$invalid">*alle markierten Felder sind Pflichtfelder</span>
In your send()
function, you better add message
as a parameter. You can also use ng-submit
on the form tag instead.
Upvotes: 1