I'm using ngMessages to display error messages with my form validation and this is working.
Now my problem is when I submit the form I want to change the classes from being valid (green border) to their normal state, which is just css on the inputs. Also if all the fields are valid a text message should display above the form that the form has been sent but it doesn't seem to be working with the $valid.
After a few seconds the message disappears.
Plunker
my code
css
input {
background-color: #fff;
border: 1px solid darkgray;
margin-top: 20px;
width: 400px;
height: 45px;
padding: 0 10px;
}
.invalid-field {
border: 1px solid red;
}
.valid-field {
border: 1px solid green;
}
.error {
color: red;
}
.sent {
color: green;
}
html/angular
<form novalidate name="contactForm">
<div ng-messages="contactForm.$valid" ng-if="contactForm.$submitted">
<div ng-message="valid">
<span class="sent">Your message has been sent!</span>
</div>
</div>
<input ng-class="{'invalid-field': contactForm.nameField.$touched || contactForm.$submitted, 'valid-field': contactForm.nameField.$valid}"
type="text" name="nameField" placeholder="Full name*"
ng-model="contactName"
minlength="2"
required >
<div ng-messages="contactForm.nameField.$error" ng-if="contactForm.$submitted || contactForm.nameField.$touched">
<div ng-message="required">
<span class="error">Name is required</span>
</div>
<div ng-message="minlength">
<span class="error">Name must be 2 characters long</span>
</div>
</div>
<input ng-class="{'invalid-field': contactForm.emailField.$touched || contactForm.$submitted, 'valid-field': contactForm.emailField.$valid}"
type="email" name="emailField" placeholder="Email*"
ng-model="contactEmail"
required>
<div ng-messages="contactForm.emailField.$error" ng-if="contactForm.$submitted || contactForm.emailField.$touched">
<div ng-message="required"><span class="error">Email is required</span></div>
<div ng-message="email"><span class="error">Email is not valid</span></div>
</div>
<button class="send-btn" type="submit">Send form</button>
</form>