Ionic: Showing an alert controller with a checkbox and text input

孤者浪人 提交于 2020-01-20 05:09:09

问题


I am trying to show a checkbox along with a text input field. (Ionic 3.5.3)

The checkbox is not showing up. I looked at another SO thread for a similar question. The code seems to be the same as what I am doing.

The code:

let alert = this.alert.create({
      title: 'Name your trip',
      inputs: [
      {
        name: 'name',
        placeholder: 'Your trip name',
      },
      {
         name: 'gpsxy',
         type:'checkbox',
         checked:true,
         label:'Log GPS co-ords',
         value:"true"
      }
    ],

      buttons: [{
        text: 'Cancel',
        role: 'cancel',
        handler: data => {
        }
      },
      {
        text: 'Ok',
        handler: data => {
      }],
    });
    alert.present();

And here is the screenshot:


回答1:


Just like you can see in the docs

Alerts can also include several different inputs whose data can be passed back to the app. Inputs can be used as a simple way to prompt users for information. Radios, checkboxes and text inputs are all accepted, but they cannot be mixed. For example, an alert could have all radio button inputs, or all checkbox inputs, but the same alert cannot mix radio and checkbox inputs. Do note however, different types of "text"" inputs can be mixed, such as url, email, text, etc. If you require a complex form UI which doesn't fit within the guidelines of an alert then we recommend building the form within a modal instead.

So I'm afraid that it's not possible to do that in Ionic :(



来源:https://stackoverflow.com/questions/45355758/ionic-showing-an-alert-controller-with-a-checkbox-and-text-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!