0

I am new to angular js and I am developing a form which has many input fields and two buttons- one for cancel and another one for submitting the form.

i am having a ng-submit="" on the form tag to recognize if the form is submitted and show some error messages.

Problem i am facing is when i click on enter 'cancel' button is triggered. How do i prevent this? I tried adding type=input on the button but it does not work.

<button type="button" ng-click="function">Cancel</button>

I cannot change the button tag to input tag as i am applying some styles and i am losing them if i change the tag.

How do I achieve this?

Thanks in advance.

UPDATE:

below is the code for button.

<div class="button-group-right" style="width:49%; float:left">
        <button  class="btn btn-large btn-tertiary btn-right" ng-click="subnmitPage()">
        <span class="btn-text">
        <span class="btn-text-container">Submit</span>
        </span>
        <span class="btn-icon">
        <i class="navigateright button-icon"></i>
        </span>
        </button>
</div>
4
  • can you show us the code used for Enter button Commented May 17, 2016 at 10:29
  • just added the code in the UPDATE section Commented May 17, 2016 at 10:34
  • both are completely same. i will edit it now Commented May 17, 2016 at 10:42
  • Just a thought. You can set tabindex = 1' for submit and tabindex = 2` for cancel button in the dom. Commented May 17, 2016 at 10:45

1 Answer 1

1

i fixed it by adding $event in my function and saying preventDefault(). code below.

in html:

 <button ng-click="subnmitPage($event)"/>

and in controller

$scope.subnmitPage=function(event){
     event.preventDefault();
}
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.