angular-xeditable icon indicating copy to clipboard operation
angular-xeditable copied to clipboard

Use Angular's built-in validations

Open nicolasgarnil opened this issue 10 years ago • 3 comments

Is it possible to use Angular's built in validations (ng-pattern, ng-minlength, etc) instead of performing them manually in a custom validation method in the onbeforesave attribute?

I would like to disable the form's save button using rowForm.$invalid but for some reason it is not working.

<tr ng-repeat="user in users">
  <!-- row inputs -->
  <td>
    <span editable-text="user.email" e-name="email" e-form="rowForm" e-required>
      {{user.email}}
    </span> 
    <!-- use my own custom validation messages  -->
    <span class="help-block" ng-show="rowForm.email.$dirty && rowForm.email.$error.required">required</span>
  </td>
  <!-- row form -->
  <td>
    <form editable-form name="rowForm" onbeforesave="save($index, $data, user.id)" ng-show="rowForm.$visible" class="form-buttons form-inline" shown="inserted == user" novalidate>
       <!-- disable button if form is invalid, doesn't work  -->
      <button type="submit" ng-disabled="rowForm.$waiting || rowForm.$invalid" class="btn btn-primary btn-sm">
        <span class="fa fa-save"></span>
        Save
      </button>
      <a type="button" ng-disabled="rowForm.$waiting" class="btn btn-default" ng-click="rowForm.$cancel()">
        Cancel
      </a>
    </form>
    <a class="btn btn-info btn-sm" ng-click="rowform.$show()" ng-show="!rowForm.$visible">
      Edit
    </a>
  </td>
</tr>

nicolasgarnil avatar Aug 04 '14 19:08 nicolasgarnil

Would also be useful to use the $pristine and $dirty properties of the form for example to not trigger an update call if the form has not changed.

nicolasgarnil avatar Aug 05 '14 19:08 nicolasgarnil

Are there any updates on this issue?

jsandeepm avatar Aug 10 '16 10:08 jsandeepm

Pull requests are welcome :)

ckosloski avatar Dec 11 '17 20:12 ckosloski