diff --git a/ionic/components/alert/alert.ts b/ionic/components/alert/alert.ts index 850fc28477..867a944c9a 100644 --- a/ionic/components/alert/alert.ts +++ b/ionic/components/alert/alert.ts @@ -32,8 +32,8 @@ export class Alert extends ViewController { this.data.subTitle = subTitle; } - setBodyText(text) { - this.data.text = text; + setBody(body) { + this.data.body = body; } addInput(input) { @@ -75,11 +75,11 @@ export class Alert extends ViewController { '

{{d.title}}

' + '

{{d.subTitle}}

' + '' + - '
{{d.text}}
' + + '
{{d.body}}
' + '
' + '
' + '
{{i.title}}
' + - '' + + '' + '
' + '
' + '
' + @@ -112,7 +112,7 @@ class AlertCmp { if (button.handler) { // a handler has been provided, run it - if (button.handler() === false) { + if (button.handler(this.getValue()) === false) { // if the return value is a false then do not close shouldClose = false; } @@ -127,9 +127,24 @@ class AlertCmp { this._viewCtrl.close(); } + getValue() { + let inputs = this.d.inputs; + if (inputs) { + if (inputs.length > 1) { + // array of values for each input + return inputs.map(i => i.input); + + } else if (inputs.length === 1) { + // single value of the one input + return inputs[0].input; + } + } + // there are no inputs + return null; + } + onPageDidLeave() { - let values = this.d.inputs.map(i => i.value); - this.d.onClose && this.d.onClose(values); + this.d.onClose && this.d.onClose(this.getValue()); } } diff --git a/ionic/components/alert/test/basic/index.ts b/ionic/components/alert/test/basic/index.ts index b61b892b88..acb2f752e2 100644 --- a/ionic/components/alert/test/basic/index.ts +++ b/ionic/components/alert/test/basic/index.ts @@ -9,7 +9,6 @@ class E2EApp { constructor(private overlay: OverlayController) { this.alertOpen = false; this.confirmOpen = false; - this.confirmResult = ''; this.promptOpen = false; this.promptResult = ''; } @@ -17,17 +16,36 @@ class E2EApp { doAlert() { let alert = Alert.create({ title: 'Alert!', - subTitle: 'My alert subtitle', - bodyText: 'My alert body text', - buttons: ['Ok'] + subTitle: 'Subtitle!!!', + buttons: ['Ok'], + onClose: () => { + this.alertOpen = false; + } }); - alert.onClose(() => { - this.alertOpen = false; + this.overlay.push(alert); + + this.alertOpen = true; + } + + doConfirm() { + let alert = Alert.create(); + alert.setTitle('Confirm!'); + alert.setBody('Body text!!!'); + alert.addButton('Cancel'); + alert.addButton({ + text: 'Ok', + handler: () => { + console.log('Confirm Ok'); + } + }); + + alert.onClose(data => { + this.confirmOpen = false; }); this.overlay.push(alert).then(() => { - this.alertOpen = true; + this.confirmOpen = true; }); } @@ -40,12 +58,12 @@ class E2EApp { }); alert.addButton({ text: 'Cancel', - handler: () => { + handler: data => { console.log('500ms delayed prompt close'); setTimeout(() => { console.log('Prompt close'); - alert.close(); + alert.close(data); }, 500); return false; @@ -53,21 +71,18 @@ class E2EApp { }); alert.addButton({ text: 'Ok', - handler: () => { - console.log('Prompt Ok'); + handler: data => { + console.log('Prompt data:', data); } }); alert.onClose(data => { this.promptOpen = false; + this.promptResult = data; }); this.overlay.push(alert).then(() => { this.promptOpen = true; }); } - - doConfirm() { - - } } diff --git a/ionic/components/alert/test/basic/main.html b/ionic/components/alert/test/basic/main.html index 928e705a0e..c86120b709 100644 --- a/ionic/components/alert/test/basic/main.html +++ b/ionic/components/alert/test/basic/main.html @@ -2,15 +2,14 @@ - +
     Alert Opened: {{alertOpen}}
+    Confirm Opened: {{confirmOpen}}
     Prompt Opened: {{promptOpen}}
     Prompt Result: {{promptResult}}
-    Confirm Opened: {{confirmOpen}}
-    Confirm Result: {{confirmResult}}