0

I want to have that after clicking submit button it check if there is something written down in input form if not the ng-class change the span color to red . I want to have red color only after submittion not all the time , here is link :

<form name="myForm" validate class="form-horizontal">

  <div class="control-group" >
    <label ng-class="{bad: ( myForm.name.$invalid && myForm.name.$pristine )  }"  >Name:</label>
    <input type="text" name="name" placeholder="Name" ng-model="user.name" required/>
    <span ng-show="isInvalid('name')" class="help-inline">Name is required</span>
    <span ng-show="isValid('name')">Great!</span>
  </div>

  <button type="submit">SUB</button>

</form>

http://plnkr.co/edit/m3dqBnpPenbY65xa3PXH?p=preview

1 Answer 1

1

you need to track whether submit button clicked or not , here u can maintain a scope variable and detect the form is submitted or not

<button type="submit" ng-click="submitted = true">SUB</button>

if some one clicked the submit then, there is a scope variable called submitted with true value

<label ng-class="{bad: ( myForm.name.$invalid && myForm.name.$pristine && submitted )  }"  >Name:</label>

here is the Plunker

Sign up to request clarification or add additional context in comments.

Comments

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.