Skip to content

Commit 46fe1ff

Browse files
committed
fix(alert): inputs have id
fixes #10603
1 parent aa287ce commit 46fe1ff

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

src/components/alert/alert-component.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { NavParams } from '../../navigation/nav-params';
99
import { NavOptions } from '../../navigation/nav-util';
1010
import { Platform } from '../../platform/platform';
1111
import { ViewController } from '../../navigation/view-controller';
12+
import { AlertInputOptions, AlertOptions, AlertButton } from './alert-options';
1213

1314

1415
/**
@@ -39,7 +40,7 @@ import { ViewController } from '../../navigation/view-controller';
3940

4041
'<template ngSwitchCase="checkbox">' +
4142
'<div class="alert-checkbox-group">' +
42-
'<button ion-button="alert-checkbox-button" *ngFor="let i of d.inputs" (click)="cbClick(i)" [attr.aria-checked]="i.checked" [disabled]="i.disabled" class="alert-tappable alert-checkbox" role="checkbox">' +
43+
'<button ion-button="alert-checkbox-button" *ngFor="let i of d.inputs" (click)="cbClick(i)" [attr.aria-checked]="i.checked" [attr.id]="i.id" [disabled]="i.disabled" class="alert-tappable alert-checkbox" role="checkbox">' +
4344
'<div class="alert-checkbox-icon"><div class="alert-checkbox-inner"></div></div>' +
4445
'<div class="alert-checkbox-label">' +
4546
'{{i.label}}' +
@@ -51,7 +52,7 @@ import { ViewController } from '../../navigation/view-controller';
5152
'<template ngSwitchDefault>' +
5253
'<div class="alert-input-group">' +
5354
'<div *ngFor="let i of d.inputs" class="alert-input-wrapper">' +
54-
'<input [placeholder]="i.placeholder" [(ngModel)]="i.value" [type]="i.type" class="alert-input">' +
55+
'<input [placeholder]="i.placeholder" [(ngModel)]="i.value" [type]="i.type" [attr.id]="i.id" class="alert-input">' +
5556
'</div>' +
5657
'</div>' +
5758
'</template>' +
@@ -73,16 +74,7 @@ import { ViewController } from '../../navigation/view-controller';
7374
export class AlertCmp {
7475
activeId: string;
7576
descId: string;
76-
d: {
77-
cssClass?: string;
78-
message?: string;
79-
title?: string;
80-
subTitle?: string;
81-
mode?: string;
82-
buttons?: any[];
83-
inputs?: any[];
84-
enableBackdropDismiss?: boolean;
85-
};
77+
d: AlertOptions;
8678
enabled: boolean;
8779
hdrId: string;
8880
id: number;
@@ -147,9 +139,9 @@ export class AlertCmp {
147139
});
148140

149141
data.inputs = data.inputs.map((input, index) => {
150-
return {
142+
let r: AlertInputOptions = {
151143
type: input.type || 'text',
152-
name: isPresent(input.name) ? input.name : index,
144+
name: isPresent(input.name) ? input.name : index + '',
153145
placeholder: isPresent(input.placeholder) ? input.placeholder : '',
154146
value: isPresent(input.value) ? input.value : '',
155147
label: input.label,
@@ -158,6 +150,7 @@ export class AlertCmp {
158150
id: isPresent(input.id) ? input.id : `alert-input-${this.id}-${index}`,
159151
handler: isPresent(input.handler) ? input.handler : null,
160152
};
153+
return r;
161154
});
162155

163156

@@ -291,7 +284,7 @@ export class AlertCmp {
291284

292285
bdClick() {
293286
if (this.enabled && this.d.enableBackdropDismiss) {
294-
let cancelBtn = this.d.buttons.find(b => b.role === 'cancel');
287+
var cancelBtn = this.d.buttons.find(b => (<AlertButton>b).role === 'cancel');
295288
if (cancelBtn) {
296289
this.btnClick(cancelBtn);
297290

src/components/alert/alert-options.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@ export interface AlertOptions {
55
message?: string;
66
cssClass?: string;
77
mode?: string;
8-
inputs?: Array<AlertInputOptions>;
9-
buttons?: Array<any>;
8+
inputs?: AlertInputOptions[];
9+
buttons?: (AlertButton|string)[];
1010
enableBackdropDismiss?: boolean;
1111
}
1212

1313
export interface AlertInputOptions {
1414
type?: string;
15-
name?: string;
15+
name?: string | number;
1616
placeholder?: string;
1717
value?: string;
1818
label?: string;
1919
checked?: boolean;
2020
disabled?: boolean;
2121
id?: string;
22+
handler?: Function;
2223
}
24+
25+
export interface AlertButton {
26+
text?: string;
27+
role?: string;
28+
handler?: Function;
29+
};

src/components/alert/alert.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
22

33
import { App } from '../app/app';
44
import { AlertCmp } from './alert-component';
5-
import { AlertOptions, AlertInputOptions } from './alert-options';
5+
import { AlertOptions, AlertInputOptions, AlertButton } from './alert-options';
66
import { isPresent } from '../../util/util';
77
import { NavOptions } from '../../navigation/nav-util';
88
import { ViewController } from '../../navigation/view-controller';
@@ -67,7 +67,7 @@ export class Alert extends ViewController {
6767
/**
6868
* @param {any} button Alert button
6969
*/
70-
addButton(button: any): Alert {
70+
addButton(button: AlertButton|string): Alert {
7171
this.data.buttons.push(button);
7272
return this;
7373
}

src/components/alert/test/basic/app.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class E2EPage {
9898
});
9999
alert.addInput({
100100
name: 'name2',
101+
id: 'name2-id',
101102
value: 'hello',
102103
placeholder: 'Placeholder 2'
103104
});

0 commit comments

Comments
 (0)