]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Handle input error in custom input text
authorChocobozzz <me@florianbigard.com>
Mon, 20 Jun 2022 14:42:21 +0000 (16:42 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 20 Jun 2022 14:42:21 +0000 (16:42 +0200)
12 files changed:
client/src/app/+admin/overview/users/user-edit/user-edit.component.html
client/src/app/+admin/overview/users/user-edit/user-password.component.html
client/src/app/+login/login.component.html
client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.html
client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html
client/src/app/+reset-password/reset-password.component.html
client/src/app/+signup/+register/steps/register-step-user.component.html
client/src/app/shared/shared-forms/dynamic-form-field.component.html
client/src/app/shared/shared-forms/dynamic-form-field.component.ts
client/src/app/shared/shared-forms/input-text.component.html
client/src/app/shared/shared-forms/input-text.component.ts
client/src/sass/class-helpers.scss

index bfa4141645242efa73bddc324754471f60bcb9dc..e484ab8b02304378fe46edb51dd94457e479c765 100644 (file)
             </ng-template>
           </my-help>
 
-          <my-input-text
-            formControlName="password" inputId="password" [ngClass]="{ 'input-error': formErrors['password'] }" autocomplete="new-password"
-          ></my-input-text>
-
-          <div *ngIf="formErrors.password" class="form-error">
-            {{ formErrors.password }}
-          </div>
+          <my-input-text formControlName="password" inputId="password" [formError]="formErrors['password']" autocomplete="new-password"></my-input-text>
         </div>
 
         <div class="form-group">
index 35f36e4659939fab133a9827d4a55e2eecc8a9ef..13f57024b3e3194fd49495879aa74468f2f68b02 100644 (file)
@@ -1,4 +1,5 @@
 <form role="form" (ngSubmit)="formValidated()" [formGroup]="form">
+
   <div class="input-group">
     <input id="password" [attr.type]="showPassword ? 'text' : 'password'" class="form-control"
       formControlName="password" [ngClass]="{ 'input-error': formErrors['password'] }"
index 834ea6e51cd359f8249760d91287b3134be9a118..aac2611c6e0be3adecbc6e0fe0a178aeda7973a4 100644 (file)
           <div class="form-group">
             <label i18n for="password">Password</label>
 
-            <my-input-text formControlName="password" inputId="password"
-                                    i18n-placeholder placeholder="Password"
-                                    [ngClass]="{ 'input-error': formErrors['password'] }"
-                                    autocomplete="current-password" [tabindex]="2"></my-input-text>
-
-            <div *ngIf="formErrors.password" class="form-error">{{ formErrors.password }}</div>
+            <my-input-text
+              formControlName="password" inputId="password" i18n-placeholder placeholder="Password"
+              [formError]="formErrors['password']" autocomplete="current-password" [tabindex]="2"
+            ></my-input-text>
           </div>
 
           <input type="submit" class="peertube-button orange-button" i18n-value value="Login" [disabled]="!form.valid">
index c9f9d8f550f83ad216cb02eaf5fd0fb1d06df912..d85be846ba76baca3769b160ce1de729ac8ac5cd 100644 (file)
   </div>
 
   <div class="form-group">
-    <my-input-text formControlName="password"
-                            id="password"
-                            i18n-placeholder placeholder="Current password"
-                            [ngClass]="{ 'input-error': formErrors['password'] }"
-                            autocomplete="current-password"></my-input-text>
-    <div *ngIf="formErrors['password']" class="form-error">
-      {{ formErrors['password'] }}
-    </div>
+    <my-input-text
+      formControlName="password" id="password" i18n-placeholder placeholder="Current password"
+      [formError]="formErrors['password']" autocomplete="current-password"
+    ></my-input-text>
   </div>
 
   <input type="submit" i18n-value value="Change email" [disabled]="!form.valid">
index f1deb42735baaca83a6ad86200152cdd65cdd30b..f961d3294706d64e5b5c1069e2985f7b79581b8e 100644 (file)
@@ -3,32 +3,20 @@
 <form role="form" (ngSubmit)="changePassword()" [formGroup]="form">
 
   <label i18n for="current-password">Change password</label>
-  <my-input-text formControlName="current-password"
-                          inputId="current-password"
-                          i18n-placeholder placeholder="Current password"
-                          [ngClass]="{ 'input-error': formErrors['current-password'] }"
-                          autocomplete="current-password"></my-input-text>
-  <div *ngIf="formErrors['current-password']" class="form-error">
-    {{ formErrors['current-password'] }}
-  </div>
+  <my-input-text
+    formControlName="current-password" inputId="current-password" i18n-placeholder placeholder="Current password"
+    [formError]="formErrors['current-password']" autocomplete="current-password"
+  ></my-input-text>
 
-  <my-input-text formControlName="new-password"
-                          inputId="new-password"
-                          i18n-placeholder placeholder="New password"
-                          [ngClass]="{ 'input-error': formErrors['new-password'] }"
-                          autocomplete="new-password"></my-input-text>
-  <div *ngIf="formErrors['new-password']" class="form-error">
-    {{ formErrors['new-password'] }}
-  </div>
+  <my-input-text
+    formControlName="new-password" inputId="new-password" i18n-placeholder placeholder="New password"
+    [formError]="formErrors['new-password']" autocomplete="new-password"
+  ></my-input-text>
 
-  <my-input-text formControlName="new-confirmed-password"
-                          inputId="new-confirmed-password"
-                          i18n-placeholder placeholder="Confirm new password"
-                          [ngClass]="{ 'input-error': formErrors['new-confirmed-password'] }"
-                          autocomplete="new-password"></my-input-text>
-  <div *ngIf="formErrors['new-confirmed-password']" class="form-error">
-    {{ formErrors['new-confirmed-password'] }}
-  </div>
+  <my-input-text
+    formControlName="new-confirmed-password" inputId="new-confirmed-password" i18n-placeholder placeholder="Confirm new password"
+    [formError]="formErrors['new-confirmed-password']" autocomplete="new-password"
+  ></my-input-text>
 
   <input type="submit" i18n-value value="Change password" [disabled]="!form.valid">
 </form>
index 1308735932163f0abcf3e3f64a57f77ce66afc60..fa53e7526be8a145c8aa5ad6b268e73cc1ba541a 100644 (file)
@@ -7,10 +7,8 @@
 
       <my-input-text
         formControlName="password" inputId="password" i18n-placeholder placeholder="Password"
-        [ngClass]="{ 'input-error': formErrors['password'] }" autocomplete="new-password"
+        [formError]="formErrors['password']" autocomplete="new-password"
       ></my-input-text>
-
-      <div *ngIf="formErrors.password" class="form-error">{{ formErrors.password }}</div>
     </div>
 
     <div class="form-group">
 
       <my-input-text
         formControlName="password-confirm" inputId="password-confirm" i18n-placeholder placeholder="Confirmed password"
-        [ngClass]="{ 'input-error': formErrors['password-confirm'] }" autocomplete="new-password"
+        [formError]="formErrors['password-confirm']" autocomplete="new-password"
       ></my-input-text>
-
-      <div *ngIf="formErrors['password-confirm']" class="form-error">{{ formErrors['password-confirm'] }}</div>
     </div>
 
     <input
index bffcf0346cc257d4cca9506364a094b00754cfe0..3e0d35006fae43be552333ac3aa55ee41ba54f86 100644 (file)
 
       <my-input-text
         formControlName="password" inputId="password"
-        [ngClass]="{ 'input-error': formErrors['password'] }" autocomplete="new-password"
+        [formError]="formErrors['password']" autocomplete="new-password"
       ></my-input-text>
-
-      <div *ngIf="formErrors.password" class="form-error">{{ formErrors.password }}</div>
     </div>
   </div>
 </form>
index 61f9ae8ff7bf07b28ffa6f4c48fccbe61eb45ecb..2dd6cf4ad68040c4f7274373cb30df800c2e6ba3 100644 (file)
@@ -18,7 +18,7 @@
     </select>
   </div>
 
-  <my-input-text *ngIf="setting.type === 'input-password'" [formControlName]="setting.name" [inputId]="setting.name"></my-input-text>
+  <my-input-text *ngIf="setting.type === 'input-password'" [formError]="formErrors['settings.name']" [formControlName]="setting.name" [inputId]="setting.name"></my-input-text>
 
   <textarea *ngIf="setting.type === 'input-textarea'" type="text" [id]="setting.name" [formControlName]="setting.name"></textarea>
 
@@ -40,7 +40,7 @@
 
   <div *ngIf="setting.type === 'html'" [innerHTML]="setting.html"></div>
 
-  <div *ngIf="setting.type !== 'markdown-text' && setting.type !== 'markdown-enhanced' && formErrors[setting.name]" class="form-error">
+  <div *ngIf="hasDedicatedFormError() && formErrors[setting.name]" class="form-error">
     {{ formErrors[setting.name] }}
   </div>
 
index b6389079792ddb00fe2e61116ec51fa67117c637..e1a1f80340205ffacd83bd88760a6a51f98ace80 100644 (file)
@@ -12,4 +12,15 @@ export class DynamicFormFieldComponent {
   @Input() form: FormGroup
   @Input() formErrors: any
   @Input() setting: RegisterClientFormFieldOptions
+
+  hasDedicatedFormError () {
+    const dedicated = new Set<RegisterClientFormFieldOptions['type']>([
+      'input-checkbox',
+      'input',
+      'select',
+      'input-textarea'
+    ])
+
+    return dedicated.has(this.setting.type)
+  }
 }
index f890c4f02d0b23ce99f511b9aeda3a2efb65df52..abb53a085638cf0301fb30d87081e362726bfdc3 100644 (file)
@@ -3,6 +3,7 @@
     [id]="inputId" [autocomplete]="autocomplete" [value]="value" [placeholder]="placeholder" [tabindex]="tabindex"
     [(ngModel)]="value" (ngModelChange)="update()" [readonly]="readonly"
     #input (click)="input.select()" (input)="update()" (change)="update()" [type]="inputType" class="form-control"
+    [ngClass]="{ 'input-error': formError }"
   />
 
   <button *ngIf="withToggle" (click)="toggle()" type="button" class="btn btn-outline-secondary" [title]="toggleTitle">
@@ -18,3 +19,5 @@
     <span class="copy-text">Copy</span>
   </button>
 </div>
+
+<div *ngIf="formError" class="form-error">{{ formError }}</div>
index ed4637c17846293cfe20ad953d067db6a2a55688..d667ed663afb0dbfa9e412b54d7f6c90fb6920b4 100644 (file)
@@ -24,6 +24,7 @@ export class InputTextComponent implements ControlValueAccessor {
   @Input() withCopy = false
   @Input() readonly = false
   @Input() show = false
+  @Input() formError: string
 
   constructor (private notifier: Notifier) { }
 
index f09d848829a9677c89b9098665546b4ec7e3d271..2994a57ae8d809cc4d16d12f3b46a4965991cc28 100644 (file)
   }
 }
 
+.input-group .input-error {
+  z-index: 3;
+}
+
 .form-error,
 .form-warning {
   display: block;
@@ -87,7 +91,9 @@
   color: $red;
 }
 
-.input-error:focus {
+// Disable red error on input focus
+.input-error:focus,
+.input-group:focus-within {
   & + .form-error,
   & + * + .form-error, // Markdown textarea
   & + * + * + .form-error {