Ionic Unable to fix maxlength for prompt input of alert controller

Im used my mobile application for ionic-3 I have some small issue, I want to set the max length dynamically, I tried but not work that Unable to fix max length for prompt input of alert controller I want to know how to do that dynamically, Thanks

 doPrompt() {
        let prompt = this.alertCtrl.create({
          title: 'Add your digit code',
          message: "",
          inputs: [
            { 


              name: 'title',

type:'number',
           placeholder: '* * * *',
              max:'4',
            },
          ],
          buttons: [
            {
              text: 'Cancel',
              handler: data => {
                console.log('Cancel clicked');
              }
            },
            {
              text: 'Save',
              handler: data => {
                console.log('Saved clicked');
              }
            }
          ]
        });
        prompt.present();
      }
    }

I wrote an AlertControlManager provider. A page sends details to the manager, the manager formats the alert, and then presents the alert. So the pages only call the manager, and the manager is the only place AlertController is injected. That way, every alert on every page has the same feel.

@AaronSterling Sir, you know any solution for this ?

I just told you how to solve it.

Dynamic data -> provider formats the data -> present alert

First, specify the ID of the input field like this:

inputs: [ { name: 'title', id: 'maxLength10', type:'number', placeholder: '* * * *', } ],

Second, present the prompt like this:

prompt.present().then(result =>{document.getElementById('maxLength10').setAttribute('maxlength','10');});

6 Likes

@Madhawa Got solution? If yes, please share here… I’m stuck on this

@mrvision2 Hi, Sorry to say but its not working. Below is my code snip:

let alert = this.alertCtrl.create({
title: ‘Zip Code’,
cssClass:‘drugselectorr forgot_email_s’,
inputs: [
{
name: ‘ZipCode’,
placeholder: ‘Enter ZipCode’,
type: ‘number’,
id: ‘maxLength10’
}
],
buttons: [
{
text:‘Cancel’,
handler: data => {

      }
    },
    {
      text: 'Submit',
      handler: data => {
        if (data.ZipCode == '') {
          let alert =this.alertCtrl.create({
            title:'Need',
            subTitle:'Need zipcode',
            cssClass:'drugselectorr needzip'
          });
          alert.present();
        }
        else {
          this.GetLatLongByZIP(data.ZipCode);
        }
      }
    }
    
  ]
});
alert.present().then(result =>{document.getElementById('maxLength10').setAttribute('maxlength','10');});