Ng-disabled not working?


#1

Im trying to implement a simple form validation.

If the input form is not touched and/or is invalid, the OK button should be disabled. Its not working, do I need a JS code as well?

Also the "required"in the input is not working too. I can still click ok without entering anything in the form and it will still be accepted as valid input. The character limit isnt working as well…all very odd.

Appreciate help on this, many thanks!

<ion-view ng-controller="MainCtrl"> 
    
      <ion-nav-buttons side="left">
        <button class="button button-icon ion-close-round" ng-click="close()"></button>
      </ion-nav-buttons>
    
      <ion-nav-buttons side="right">
        <button class="button button-large button-assertive" ng-click="submitPost()"
          ng-disabled="newPost.$invalid || newPost.$pristine">
          <b>OK</b>
        </button>
      </ion-nav-buttons>
    

      <ion-content class="padding has-header">
     
        <form name="newPost">
        	<div>
            <input type="text" 
              placeholder="input" 
              ng-model="post.title" 
              ng-maxlength="150" 
              required>
          </div>
       </form>
    
      </ion-content>
    </ion-view>

#2

I notice there’s no closing </form> tag - I’d imagine this causes problems knowing where the form ends, and there’s an extraneous class attribute on the enclosing div (although I doubt that has any effect)


#3

Hi somehow the didnt get copied over.
I made sure its added and took out the extra class …still the same though.

I have also tried to implement a @ {{ post.created | date }} but its not working too. Do I need a separate js code to timestamp and display date/time created for all the entries?