Skip to content

Commit b219de5

Browse files
committed
fix(select): do not open on form submit
Closes #5596
1 parent 154a69c commit b219de5

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

ionic/components/select/select.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class Select {
126126
private _texts: Array<string> = [];
127127
private _text: string = '';
128128
private _fn: Function;
129+
private _isOpen: boolean = false;
129130

130131
/**
131132
* @private
@@ -185,14 +186,25 @@ export class Select {
185186
}
186187
}
187188

188-
/**
189-
* @private
190-
*/
191189
@HostListener('click', ['$event'])
192190
private _click(ev) {
191+
if (ev.detail === 0) {
192+
// do not continue if the click event came from a form submit
193+
return;
194+
}
193195
ev.preventDefault();
194196
ev.stopPropagation();
197+
this._open();
198+
}
195199

200+
@HostListener('keyup.space', ['$event'])
201+
private _keyup(ev) {
202+
if (!this._isOpen) {
203+
this._open();
204+
}
205+
}
206+
207+
private _open() {
196208
if (this._disabled) return;
197209
console.debug('select, open alert');
198210

@@ -245,6 +257,11 @@ export class Select {
245257
});
246258

247259
this._nav.present(alert, alertOptions);
260+
261+
this._isOpen = true;
262+
alert.onDismiss(() => {
263+
this._isOpen = false;
264+
});
248265
}
249266

250267

ionic/components/select/test/multiple-value/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {App, Page} from 'ionic-angular';
2+
import {Control, ControlGroup} from 'angular2/common';
23

34

45
@Page({
@@ -9,6 +10,7 @@ class E2EPage {
910
carFeatures: Array<string>;
1011
pets: Array<string>;
1112
petOptions: Array<{text: string, value: string}>;
13+
authForm: ControlGroup;
1214

1315
constructor() {
1416
this.toppings = ['bacon', 'xcheese'];
@@ -21,12 +23,21 @@ class E2EPage {
2123
{ text: 'Honey Badger', value: 'honeybadger' },
2224
{ text: 'Pig', value: 'pig' },
2325
];
26+
27+
this.authForm = new ControlGroup({
28+
name: new Control(''),
29+
select: new Control('')
30+
});
2431
}
2532

2633
carChange(selectedValues) {
2734
console.log('carChange', selectedValues);
2835
}
2936

37+
onSubmit(data) {
38+
console.log('onSubmit', data);
39+
}
40+
3041
}
3142

3243

ionic/components/select/test/multiple-value/main.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,21 @@
5252
<code>pets: {{pets}}</code><br>
5353
</p>
5454

55+
<form [ngFormModel]="authForm" (ngSubmit)="onSubmit(authForm.value)">
56+
<ion-list padding-vertical>
57+
<ion-item>
58+
<ion-input ngControl="name" type="text"></ion-input>
59+
</ion-item>
60+
<ion-item class="no-border">
61+
<ion-label>Select</ion-label>
62+
<ion-select multiple="true" ngControl="select">
63+
<ion-option>1</ion-option>
64+
<ion-option>2</ion-option>
65+
<ion-option>3</ion-option>
66+
</ion-select>
67+
</ion-item>
68+
<button full block class="no-margin" type="submit">Submit</button>
69+
</ion-list>
70+
</form>
71+
5572
</ion-content>

0 commit comments

Comments
 (0)