1

I made a simple form in html with angular and bootstrap. My problem is that when I press enter in an input, it calls my submit method from ng-click.

<form id="detaliiCursa" class="form-horizontal">
  <h3> Detaliile cursei </h3>

  <div class="form-group">
    <label class="col-md-3 control-label">Sursa:</label>

    <div class="col-md-8">
      <input id="sourcePoint" type="text" class="form-control" name="sourcePoint" ng-model="detaliiCursa.sursa"/>
    </div>
  </div>

  <div class="form-group">
    <label class="col-md-3 control-label">Destinatie:</label>

    <div class="col-md-8">
      <input id="destinationPoint" type="text" class="form-control" name="destinationPoint" ng-model="detaliiCursa.destinatie"/>
    </div>
  </div>

  <div class="form-group">
    <div class="col-xs-9 col-xs-offset-3">
      <button type="submit" class="btn btn-primary" name="submit" value="submit" ng-click="submit()">Submit</button>
    </div>
  </div>
</form>

Do you know how can I call "submit()" only when I press Submit button?

Thanks.

thanksd
  • 54,176
  • 22
  • 157
  • 150
Dorin
  • 2,167
  • 4
  • 20
  • 32

1 Answers1

4

You could change your button type from submit to button. While input type is submit it tries to submit a form on enter click of any input element of the form.

HTML

<div class="form-group">
  <div class="col-xs-9 col-xs-offset-3">
    <button type="button" class="btn btn-primary" name="submit" value="submit" ng-click="submit()">Submit</button>
  </div>
</div>

Working Plunkr

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299