ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Datetime Feature - open component from code without user click event

Open lbickston opened this issue 10 years ago • 11 comments

It would be great if we could open the Datetime component just like an Alert component. This wouldn't require user interaction. This would make it much more flexible.

Which Ionic Version? or 2.x

lbickston avatar Jun 08 '16 02:06 lbickston

currently exists a workaround to do this without user interaction?

dpsoft avatar Jun 10 '16 22:06 dpsoft

Since it uses the Picker API underneath, you can call the Picker and create it that way, this isn't well documented: http://ionicframework.com/docs/v2/api/components/picker/Picker/

openPicker() {
  let picker = Picker.create({
    columns: [
      {
        columnWidth: "144px",
        name: "month",
        options: ["January", "February", "March"],
        selectedIndex: 0
      },
      {
        columnWidth: "144px",
        name: "year",
        options: ["90", "91", "92"],
        selectedIndex: 0
      },
    ],
    buttons: [
    {
      text: "Cancel",
      role: 'cancel',
      handler: () => {
        console.log("Clicked cancel")
      }
    },
    {
      text: "Done",
      handler: (data: any) => {
        console.log("Clicked done with", data);
      }
    }
  ]
  });

  this.nav.present(picker);
}

Hope that helps! See the Picker code for more info: https://github.com/driftyco/ionic/blob/2.0/src/components/picker/picker.ts

brandyscarney avatar Jun 14 '16 22:06 brandyscarney

Agreed, this would be a nice improvement to the framework.

danbucholtz avatar Jun 28 '16 21:06 danbucholtz

For this, the user's component could have a template variable, like <ion-datetime #myDatetime/>. Then @ViewChild('myDatetime') can be used to find the component. Next with that reference they can call present(). But I don't believe the present methods are exposed on something like ion-datetime or ion-select, so that's all we'll have to do (along with docs on how to do it).

adamdbradley avatar Jun 28 '16 21:06 adamdbradley

any improvements on this issue?

comfortme avatar Nov 05 '16 20:11 comfortme

by the way i found this article that shows a nice little workaround similar to @adamdbradley 's solution, https://blog.jarmemori.es/tech/2016/09/14/display_ionic_datetime_picker_programmatically.html

comfortme avatar Nov 05 '16 21:11 comfortme

+1

gigocabrera avatar Jan 22 '17 17:01 gigocabrera

Hello everyone! Thanks for the feature request. I'm going to move this issue over to our internal list of feature requests for evaluation. We are continually prioritizing all requests that we receive with outstanding issues. We are extremely grateful for your feedback, but it may not always be our next priority. I'll copy the issue back to this repository when we have begun implementation. Thanks!

jgw96 avatar Feb 06 '17 20:02 jgw96

This issue was moved to driftyco/ionic-feature-requests#44

jgw96 avatar Feb 06 '17 20:02 jgw96

Any news on that since @jqw96 mentioned a feature request that was closed.

gtcdevop avatar Sep 19 '17 22:09 gtcdevop

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Sep 02 '18 01:09 ionitron-bot[bot]