0

I want to preven form submission for a specific user type, preferably without having to edit something in the controller and without using an any type input-field? So basically something like this:

<form>
  <div class ="alert" 
       ng-if="user.type='not-allowed'" 
       maybe-an-invalidate-directive>
      <p>No! Don't!</p>

      <!-- or something like this ??? -->
      <input type ="hidden" 
             required
             ng-model="'false'">
  </div>
 .... 
</form>

While the first one should be definately possible, I would be happy to hear about a more straightforward solution.

EDIT:

After thinking about it for a while, I figured that what I want to do, is not making the form invalid, but to disable it. For a solution see this question.

Community
  • 1
  • 1
hugo der hungrige
  • 12,382
  • 9
  • 57
  • 84

1 Answers1

1

You can use the ng-submit directive on your form element, and have it return false if you don't want it to submit.

<form ng-submit="user.type !== 'not-allowed' && controller.function()">
Brian Glaz
  • 15,468
  • 4
  • 37
  • 55