Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngClass disappears with multiple conditions #5422

Closed
KerimBayramoglu opened this issue Nov 9, 2018 · 1 comment
Closed

ngClass disappears with multiple conditions #5422

KerimBayramoglu opened this issue Nov 9, 2018 · 1 comment
Labels
lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:duplicate Issues that are a duplicate of a previous issue

Comments

@KerimBayramoglu
Copy link

KerimBayramoglu commented Nov 9, 2018

Prettier 1.15.1
Playground link

# Options (if any):
angular

Input:

<div class="form-group">
    <input type="password" [ngClass]="{
        'is-invalid':
          (registerForm.get('confirmPassword').errors &&
           registerForm.get('confirmPassword').touched) ||
          (registerForm.get('confirmPassword').touched &&
          registerForm.hasError('mismatch'))
      }"
      class="form-control" formControlName="confirmPassword" placeholder="confirm password" />
    <div class="invalid-feedback" *ngIf="
        registerForm.get('confirmPassword').hasError('required') &&
        registerForm.get('confirmPassword').touched
      ">
      Wachtwoord vereist!
    </div>
    <div class="invalid-feedback" *ngIf="
        registerForm.hasError('mismatch') &&
        registerForm.get('confirmPassword').touched
      ">
      Wachtwoorden komen niet overeen!
    </div>
  </div>

Output:

<div class="form-group">
  <input
    type="password"
    [ngClass]="{
      '':
        (registerForm.get('confirmPassword').errors &&
          registerForm.get('confirmPassword').touched) ||
        (registerForm.get('confirmPassword').touched &&
          registerForm.hasError('mismatch'))
    }"
    class="form-control"
    formControlName="confirmPassword"
    placeholder="confirm password"
  />
  <div
    class="invalid-feedback"
    *ngIf="
      registerForm.get('confirmPassword').hasError('required') &&
      registerForm.get('confirmPassword').touched
    "
  >
    Wachtwoord vereist!
  </div>
  <div
    class="invalid-feedback"
    *ngIf="
      registerForm.hasError('mismatch') &&
      registerForm.get('confirmPassword').touched
    "
  >
    Wachtwoorden komen niet overeen!
  </div>
</div>

Expected behavior:

the class 'is-invalid' should not disappear when using OR '||'

@ikatyang
Copy link
Member

ikatyang commented Nov 9, 2018

Hi, this should be fixed by #5387, we plan to release a patch tomorrow.

Prettier pr-5387
Playground link

--parser angular

Input:

<div class="form-group">
    <input type="password" [ngClass]="{
        'is-invalid':
          (registerForm.get('confirmPassword').errors &&
           registerForm.get('confirmPassword').touched) ||
          (registerForm.get('confirmPassword').touched &&
          registerForm.hasError('mismatch'))
      }"
      class="form-control" formControlName="confirmPassword" placeholder="confirm password" />
    <div class="invalid-feedback" *ngIf="
        registerForm.get('confirmPassword').hasError('required') &&
        registerForm.get('confirmPassword').touched
      ">
      Wachtwoord vereist!
    </div>
    <div class="invalid-feedback" *ngIf="
        registerForm.hasError('mismatch') &&
        registerForm.get('confirmPassword').touched
      ">
      Wachtwoorden komen niet overeen!
    </div>
  </div>

Output:

<div class="form-group">
  <input
    type="password"
    [ngClass]="{
      'is-invalid':
        (registerForm.get('confirmPassword').errors &&
          registerForm.get('confirmPassword').touched) ||
        (registerForm.get('confirmPassword').touched &&
          registerForm.hasError('mismatch'))
    }"
    class="form-control"
    formControlName="confirmPassword"
    placeholder="confirm password"
  />
  <div
    class="invalid-feedback"
    *ngIf="
      registerForm.get('confirmPassword').hasError('required') &&
      registerForm.get('confirmPassword').touched
    "
  >
    Wachtwoord vereist!
  </div>
  <div
    class="invalid-feedback"
    *ngIf="
      registerForm.hasError('mismatch') &&
      registerForm.get('confirmPassword').touched
    "
  >
    Wachtwoorden komen niet overeen!
  </div>
</div>

@ikatyang ikatyang closed this as completed Nov 9, 2018
@ikatyang ikatyang marked this as a duplicate of #5367 Nov 9, 2018
@ikatyang ikatyang added lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular) type:duplicate Issues that are a duplicate of a previous issue labels Nov 9, 2018
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Feb 7, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:duplicate Issues that are a duplicate of a previous issue
Projects
None yet
Development

No branches or pull requests

2 participants