feat: AlertController inputs should be having minlength, maxlength options for text fields

Feature Request

Ionic version:
[x] 5.x

Describe the Feature Request
As sometimes I need to show alert user and asking him for inputs alert AlertInput got options for min/max and seems those working for numeric to date fields, but what if I want to limit the length of the text that user provide, so I think maxlength and minlength should be added.

Describe Preferred Solution
Just adding these to AlertInput and apply the change to the rendered input.

Additional Context
This is been requested in the forum and the solution provided with “hack” but seems is not working for some reason.
https://forum.ionicframework.com/t/ionic-unable-to-fix-maxlength-for-prompt-input-of-alert-controller/119472

2 thoughts on “feat: AlertController inputs should be having minlength, maxlength options for text fields

  1. @liamdebeasi perhaps we can have a new generic “attr” option that can set custom attributes for inputs. For example like this:

    let alert = this.alertCtrl.create({
        title: 'Login',
        inputs: [
          {
            name: 'pin',
            placeholder: 'Pin Code',
            type: 'password',
            attr: { 
                    maxLength: 4,
                    inputmode: 'numeric',
                    ...
            }
          }
        ],
        buttons: [
          {
            text: 'Cancel',
            role: 'cancel'
          },
          {
            text: 'Save',
            handler: data => {
              console.log('Save clicked');
            }
          }
        ]
      });
      alert.present();
    }
    
  2. Thanks for the feature request. This has been resolved via #21365 and will be available in an upcoming release of Ionic Framework. Thanks to @cerkiner for all the hard work in getting this feature done! 🎉