Skip to content

Commit

Permalink
Merge pull request #8847 from driftyco/fix/option
Browse files Browse the repository at this point in the history
fix(select): emit the ionSelect option when selecting an option
  • Loading branch information
manucorporat authored Oct 22, 2016
2 parents 8dd6673 + 2eed5e2 commit e68b5fc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/components/alert/alert-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ export class AlertCmp {
label: input.label,
checked: !!input.checked,
disabled: !!input.disabled,
id: 'alert-input-' + this.id + '-' + index
id: 'alert-input-' + this.id + '-' + index,
handler: isPresent(input.handler) ? input.handler : null,
};
});

Expand Down Expand Up @@ -237,12 +238,20 @@ export class AlertCmp {
input.checked = (checkedInput === input);
});
this.activeId = checkedInput.id;

if (checkedInput.handler) {
checkedInput.handler(checkedInput);
}
}
}

cbClick(checkedInput: any) {
if (this.enabled) {
checkedInput.checked = !checkedInput.checked;

if (checkedInput.handler) {
checkedInput.handler(checkedInput);
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
handler: () => {
this.onChange(input.value);
this.ionChange.emit(input.value);
input.ionSelect.emit(input.value);
}
};
}));
Expand All @@ -319,7 +320,14 @@ export class Select extends Ion implements AfterContentInit, ControlValueAccesso
label: input.text,
value: input.value,
checked: input.selected,
disabled: input.disabled
disabled: input.disabled,
handler: (selectedOption: any) => {
// Only emit the select event if it is being checked
// For multi selects this won't emit when unchecking
if (selectedOption.checked) {
input.ionSelect.emit(input.value);
}
}
};
});

Expand Down
4 changes: 4 additions & 0 deletions src/components/select/test/multiple-value/app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class E2EPage {
console.log('onSubmit', data);
}

toppingsSelect(selectedValue: any) {
console.log('Selected', selectedValue);
}

}


Expand Down
2 changes: 1 addition & 1 deletion src/components/select/test/multiple-value/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ion-option value="mushrooms">Mushrooms</ion-option>
<ion-option value="onions">Onions</ion-option>
<ion-option value="pepperoni">Pepperoni</ion-option>
<ion-option value="pineapple">Pineapple</ion-option>
<ion-option value="pineapple" (ionSelect)="toppingsSelect($event)">Pineapple</ion-option>
<ion-option value="sausage">Sausage</ion-option>
<ion-option value="Spinach">Spinach</ion-option>
</ion-select>
Expand Down
8 changes: 6 additions & 2 deletions src/components/select/test/single-value/app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ export class E2EPage {
console.log('Gaming Select, Change value:', selectedValue);
}

stpSelect() {
console.log('STP selected');
musicSelect(selectedValue: any) {
console.log('Music selected', selectedValue);
}

notificationSelect(selectedValue: any) {
console.log('Notification select', selectedValue);
}

statusChange(ev: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/select/test/single-value/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<ion-option value="enable">Enable</ion-option>
<ion-option value="mute">Mute</ion-option>
<ion-option value="mute_week">Mute for a week</ion-option>
<ion-option value="mute_year">Mute for a year</ion-option>
<ion-option value="mute_year" (ionSelect)="notificationSelect($event)">Mute for a year</ion-option>
</ion-select>
</ion-item>

Expand All @@ -61,7 +61,7 @@
<ion-option>Pearl Jam</ion-option>
<ion-option>Smashing Pumpkins</ion-option>
<ion-option>Soundgarden</ion-option>
<ion-option (ionSelect)="stpSelect()">Stone Temple Pilots</ion-option>
<ion-option (ionSelect)="musicSelect($event)">Stone Temple Pilots</ion-option>
</ion-select>
</ion-item>

Expand Down

0 comments on commit e68b5fc

Please sign in to comment.