Reputation: 591
I am working with ui-select, and whenever I press enter to select some searched results, the result is selected and the form directly goes on to submit. I cant figure it out, what is the problem.
Here is the HTML I'm using
<form>
<div class="form-group">
<label class="col-sm-3 control-label">Address</label>
<div class="col-sm-5">
<input type="text" ng-model="address.street" class="form-control" placeholder="e.g. NUST Campus, H-12">
<div class="form_wrapper_error">
<p ng-show='addressError'>{{addressError}}</p>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">City/Town</label>
<div class="col-sm-5">
<!-- <location-autocomplete bind-value="address.city" coordinates="cityAddInitialCoordinates" placeholder="e.g. Islamabad"> -->
<ui-select ng-model="$parent.address.city"
theme="select2"
reset-search-input="true"
title="Select City">
<ui-select-match allow-clear="true" placeholder="Select City">{{$select.selected}}</ui-select-match>
<ui-select-choices repeat="city as city in cities track by $index"
refresh="refreshLocation($select.search)"
refresh-delay="0">
<div ng-bind-html="city | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
<div class="form_wrapper_error">
<p ng-show='cityError'>{{cityError}}</p>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Zip</label>
<div class="col-sm-5">
<input type="text" ng-model="address.zip" class="form-control" placeholder="e.g. 44000">
<div class="form_wrapper_error">
<p ng-show='zipError'>{{zipError}}</p>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-8">
<button class="btn btn-primary buttt" ng-click="addAddress()">Add Address</button>
</div>
</div>
</form>
Upvotes: 1
Views: 2965
Reputation: 210
If anyone still struggles with this issue, I found a solution\work around.
Add skip-focusser="true"
to your ui-select like so:
<ui-select ng-model="$parent.ngModel" theme="bootstrap" class="input-xs" skip-focusser="true">
<ui-select-match >{{$select.selected.description}}</ui-select-match>
<ui-select-choices repeat="item in options | orderBy :'code' | filter: $select.search">
<div ng-bind-html="item.description | highlight: $select.search"></div>
</ui-select-choices>
This will remove the focus from the select element and therfore the Enter key will not reopen the dropdown menu.
Upvotes: 0
Reputation: 591
Solution Found: I was using <button>
, and the default type of button is submit, so I had to specify the type="button", and the issue is fixed....
Reference: Found in UI-Select Pull Requests...
Upvotes: 3