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

bug: Ion-input is broken with 4.7.x

Open eulerchavez opened this issue 4 years ago • 4 comments

Bug Report

Ionic version:

[x] 4.7.x

Current behavior:

Ionic input control not working and refreshing UI as expected

Expected behavior:

Prevent write value on disabled ion-input control and Change detection should refresh the UI

Grabación de pantalla 2019-08-13 a las 11 50 38

Related code:

<!-- Anticipo a rentas incluido -->
            <ion-col size-xs="12" size-lg="4">
              <ion-item mode="md" class="item-form-group switch">
                <ion-label (click)="anticipoARentasIncluido.setValue(!anticipoARentasIncluido.value)">
                  Anticipo a rentas incluido
                </ion-label>
                <ion-toggle formControlName="AnticipoARentasIncluido" (ionChange)="handleAnticipoRentasIncluido($event)"></ion-toggle>
              </ion-item>
            </ion-col>

            <!-- Anticipo a rentas con IVA -->
            <ion-col size-xs="12" size-lg="4">
              <ion-item mode="md" class="item-form-group" [disabled]="anticipoARentasIncluido.value != true">
                <ion-label position="stacked">Anticipo a rentas con IVA</ion-label>
                <ion-input #inputAnticipoRentas type="text" inputmode="numeric" maxlength="13"
                  formControlName="AnticipoARentas" (ionChange)="handleCommissionsPercent($event)"
                  [brmasker]="{money: true, thousand: ',',  decimalCaracter: '.', decimal: '2'}">
                  <ion-icon name="logo-usd" slot="start" class="money-icon"></ion-icon>
                </ion-input>
              </ion-item>
              <div class="error-container" *ngIf="anticipoARentas.touched == true && anticipoARentas.errors">
                <div class="error-message" *ngIf="anticipoARentas.errors['required']">
                  <ion-icon name="information-circle-outline" aria-label="invalid input"></ion-icon>
                  <span>Campo obligatorio</span>
                </div>
              </div>
            </ion-col>
handleAnticipoRentasIncluido(event: CustomEvent) {

    const value = event.detail['checked'];

    if (value == true) {

      this.anticipoARentas.setValidators([Validators.required]);
      this.anticipoARentas.updateValueAndValidity();
      this.changeDetectorRef.detectChanges();
      this.anticipoARentas.markAsTouched();
      
    } else {
      
      this.anticipoARentas.clearValidators();
      this.anticipoARentas.updateValueAndValidity();
      this.changeDetectorRef.detectChanges();
    }
  }

Ionic info:

Ionic:

   Ionic CLI                     : 5.1.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.7.4
   @angular-devkit/build-angular : 0.13.0
   @angular-devkit/schematics    : 7.2.3
   @angular/cli                  : 7.3.1
   @ionic/angular-toolkit        : 1.4.0

Cordova:

   Cordova CLI       : 9.0.0 ([email protected])
   Cordova Platforms : android 8.0.0, ios 5.0.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 13 other plugins)

Utility:

   cordova-res : not installed
   native-run  : 0.2.7 (update available: 0.2.8)

System:

   ios-deploy : 1.9.4
   ios-sim    : 8.0.1
   NodeJS     : v10.16.0 (/usr/local/bin/node)
   npm        : 6.9.0
   OS         : macOS Mojave
   Xcode      : Xcode 10.2.1 Build version 10E1001

eulerchavez avatar Aug 13 '19 17:08 eulerchavez

Thanks for the issue. Are you able to provide a Stackblitz/repo with a reproduction of the issue? I am unable to reproduce this issue on my end. You can use this link as a base Stackblitz: https://stackblitz.com/edit/ionic-v4-angular-tabs

I have provided a Stackblitz of a working ion-input + forms demo here: https://stackblitz.com/edit/ionic-v4-angular-tabs-fmeseo.

Thanks!

liamdebeasi avatar Aug 15 '19 14:08 liamdebeasi

Thanks for the issue. Are you able to provide a Stackblitz/repo with a reproduction of the issue? I am unable to reproduce this issue on my end. You can use this link as a base Stackblitz: https://stackblitz.com/edit/ionic-v4-angular-tabs

I have provided a Stackblitz of a working ion-input + forms demo here: https://stackblitz.com/edit/ionic-v4-angular-tabs-fmeseo.

Thanks!

Hi there,

In this Stackblitz I was able to reproduce all the issues and one more, when I use markAsTouched, the input not display the "red line".

https://stackblitz.com/edit/ionic-v4-angular-tabs-z2mmyk

Thanks 🙏

eulerchavez avatar Aug 15 '19 16:08 eulerchavez

Apologies for the delay in response. I was able to reproduce this and will look into a fix. As a temporary workaround, you can set the disabled property directly on the ion-input rather than the ion-item. Thanks!

liamdebeasi avatar Oct 28 '19 19:10 liamdebeasi

Hi there,

We are proposing some changes to form components that seek to resolve this issue. We would love your feedback on these proposed changes! You can read more about the changes and leave comments here: https://github.com/ionic-team/ionic-framework/discussions/25661

liamdebeasi avatar Aug 02 '22 21:08 liamdebeasi

Thanks for the report. In Ionic 7 we will be introducing a new syntax for using form components such as ion-input. You can find a summary of the changes here: https://github.com/ionic-team/ionic-framework/discussions/25661

The reported issue is fixed with this new syntax. Work to update ion-input to use this new syntax has been completed, so I am going mark this issue as resolved. We plan to have a public beta period for Ionic 7 in the future. You can visit the Ionic Blog, Ionic Twitter, or our GitHub Releases Page to be notified when the Ionic 7 beta is released. Let me know if you have any questions. Thanks!

liamdebeasi avatar Nov 15 '22 16:11 liamdebeasi

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 Dec 15 '22 17:12 ionitron-bot[bot]