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.

1
  • 1
    If you downvote, please explain. Commented Oct 2, 2014 at 19:22

1 Answer 1

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()">
Sign up to request clarification or add additional context in comments.

3 Comments

Interesting! How would I use it in conjunction with a submit function on ng-submit, e.g. <form ng-submit="user.type !== 'not-allowed; submit()'">
Updated my answer. If first expression is false, controller.function won't be called.
Don't mind the downvoters, I like your answer! Almost exactly what I was looking for.

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.