MOBILE-2428 core: Fix and complete input errors

main
Dani Palou 2018-06-06 13:17:18 +02:00
parent 7c08fb4b77
commit d61a2e597c
9 changed files with 34 additions and 7 deletions

View File

@ -10,8 +10,10 @@
</ion-item>
<!-- Edit. -->
<ion-item *ngIf="edit && field && field.shortname" [formGroup]="form">
<ion-label [core-mark-required]="field.required">{{ field.name }}</ion-label>
<ion-label>
<span [core-mark-required]="field.required">{{ field.name }}</span>
<core-input-errors [control]="form.controls[field.modelName]"></core-input-errors>
</ion-label>
<ion-checkbox item-end [formControlName]="field.modelName">
</ion-checkbox>
<core-input-errors [control]="form.controls[field.modelName]" [errorMessages]="errors"></core-input-errors>
</ion-item>

View File

@ -7,4 +7,5 @@
<ion-item *ngIf="edit && field && field.shortname" text-wrap [formGroup]="form">
<ion-label stacked [core-mark-required]="field.required">{{ field.name }}</ion-label>
<ion-datetime [formControlName]="field.modelName" [placeholder]="'core.choosedots' | translate" [displayFormat]="field.format" [max]="field.max" [min]="field.min"></ion-datetime>
<core-input-errors item-content [control]="form.controls[field.modelName]"></core-input-errors>
</ion-item>

View File

@ -10,4 +10,5 @@
<ion-option value="">{{ 'core.choosedots' | translate }}</ion-option>
<ion-option *ngFor="let option of field.options" [value]="option">{{option}}</ion-option>
</ion-select>
<core-input-errors item-content [control]="form.controls[field.modelName]"></core-input-errors>
</ion-item>

View File

@ -7,4 +7,5 @@
<ion-item *ngIf="edit && field && field.shortname" text-wrap [formGroup]="form">
<ion-label stacked [core-mark-required]="field.required">{{ field.name }}</ion-label>
<ion-input [type]="field.inputType" [formControlName]="field.modelName" [placeholder]="field.name" maxlength="{{field.maxlength}}"></ion-input>
<core-input-errors item-content [control]="form.controls[field.modelName]"></core-input-errors>
</ion-item>

View File

@ -5,6 +5,9 @@
</ion-item>
<!-- Edit. -->
<ion-item *ngIf="edit && field && field.shortname" text-wrap [formGroup]="form">
<ion-label stacked [core-mark-required]="field.required">{{ field.name }}</ion-label>
<ion-label stacked>
<span [core-mark-required]="field.required">{{ field.name }}</span>
<core-input-errors [control]="control"></core-input-errors>
</ion-label>
<core-rich-text-editor item-content [control]="control" [placeholder]="field.name"></core-rich-text-editor>
</ion-item>

View File

@ -1,7 +1,15 @@
<div class="core-input-error-container" role="alert" *ngIf="(formControl && formControl.dirty && !formControl.valid) || errorText">
<ng-container *ngIf="formControl && formControl.dirty && !formControl.valid">
<ng-container *ngFor="let error of errorKeys">
<div *ngIf="formControl.hasError(error)" class="core-input-error">{{errorMessages[error]}}</div>
<div *ngIf="formControl.hasError(error)" class="core-input-error">
<span *ngIf="errorMessages[error]">{{errorMessages[error]}}</span>
<span *ngIf="!errorMessages[error] && error == 'max' && formControl.errors.max">
{{ 'core.login.invalidvaluemax' | translate:{$a: formControl.errors.max.max} }}
</span>
<span *ngIf="!errorMessages[error] && error == 'min' && formControl.errors.min">
{{ 'core.login.invalidvaluemin' | translate:{$a: formControl.errors.min.min} }}
</span>
</div>
</ng-container>
</ng-container>
<div *ngIf="errorText" class="core-input-error">{{ errorText }}</div>

View File

@ -75,7 +75,9 @@ export class CoreInputErrorsComponent implements OnInit, OnChanges {
this.errorMessages.time = this.errorMessages.time || this.translate.instant('core.login.invalidtime');
this.errorMessages.url = this.errorMessages.url || this.translate.instant('core.login.invalidurl');
// @todo: Check how to handle min/max errors once we have a test case to use. Also, review previous errors.
// Set empty values by default, the default error messages will be built in the template when needed.
this.errorMessages.max = this.errorMessages.max || '';
this.errorMessages.min = this.errorMessages.min || '';
}
/**

View File

@ -181,6 +181,7 @@ export class CoreRichTextEditorComponent implements AfterContentInit, OnDestroy
} else {
// Don't emit event so our valueChanges doesn't get notified by this change.
this.control.setValue(this.editorElement.innerHTML, {emitEvent: false});
this.control.markAsDirty();
this.textarea.value = this.editorElement.innerHTML;
}
} else {
@ -189,6 +190,7 @@ export class CoreRichTextEditorComponent implements AfterContentInit, OnDestroy
} else {
// Don't emit event so our valueChanges doesn't get notified by this change.
this.control.setValue(this.textarea.value, {emitEvent: false});
this.control.markAsDirty();
}
}
@ -240,6 +242,11 @@ export class CoreRichTextEditorComponent implements AfterContentInit, OnDestroy
* Treating videos and audios in here is complex, so if a user manually adds one he won't be able to play it in the editor.
*/
protected treatExternalContent(): void {
if (!this.sitesProvider.isLoggedIn()) {
// Only treat external content if the user is logged in.
return;
}
const elements = Array.from(this.editorElement.querySelectorAll('img')),
siteId = this.sitesProvider.getCurrentSiteId(),
canDownloadFiles = this.sitesProvider.getCurrentSite().canDownloadFiles();

View File

@ -128,9 +128,11 @@
<p><a [href]="settings.sitepolicy" core-link capture="false">{{ 'core.login.policyagreementclick' | translate }}</a></p>
</ion-item>
<ion-item text-wrap>
<ion-label core-mark-required="true">{{ 'core.login.policyaccept' | translate }}</ion-label>
<ion-checkbox item-end name="policyagreed" formControlName="policyagreed"></ion-checkbox>
<ion-label>
<span [core-mark-required]="true">{{ 'core.login.policyaccept' | translate }}</span>
<core-input-errors [control]="signupForm.controls.policyagreed" [errorMessages]="policyErrors"></core-input-errors>
</ion-label>
<ion-checkbox item-end name="policyagreed" formControlName="policyagreed"></ion-checkbox>
</ion-item>
</ng-container>