Merge pull request #2736 from dpalou/MOBILE-3722
MOBILE-3722 core: Set default min and max for datetimesmain
commit
1220b5dd28
|
@ -32,7 +32,8 @@
|
||||||
{{ 'core.date' | translate }}
|
{{ 'core.date' | translate }}
|
||||||
</h2>
|
</h2>
|
||||||
</ion-label>
|
</ion-label>
|
||||||
<ion-datetime formControlName="timestart" [placeholder]="'core.date' | translate" [displayFormat]="dateFormat">
|
<ion-datetime formControlName="timestart" [placeholder]="'core.date' | translate" [displayFormat]="dateFormat"
|
||||||
|
[max]="maxDate" [min]="minDate">
|
||||||
</ion-datetime>
|
</ion-datetime>
|
||||||
<core-input-errors [control]="form.controls.timestart" [errorMessages]="errors"></core-input-errors>
|
<core-input-errors [control]="form.controls.timestart" [errorMessages]="errors"></core-input-errors>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
@ -165,9 +166,10 @@
|
||||||
<ion-item button (click)="selectDuration('1')">
|
<ion-item button (click)="selectDuration('1')">
|
||||||
<ion-radio slot="end" value="1"></ion-radio>
|
<ion-radio slot="end" value="1"></ion-radio>
|
||||||
<ion-label>{{ 'addon.calendar.durationuntil' | translate }}</ion-label>
|
<ion-label>{{ 'addon.calendar.durationuntil' | translate }}</ion-label>
|
||||||
<ion-datetime formControlName="timedurationuntil"
|
<ion-datetime formControlName="timedurationuntil" [max]="maxDate" [min]="minDate"
|
||||||
[placeholder]="'addon.calendar.durationuntil' | translate"
|
[placeholder]="'addon.calendar.durationuntil' | translate"
|
||||||
[displayFormat]="dateFormat" [disabled]="form.controls.duration.value != 1"></ion-datetime>
|
[displayFormat]="dateFormat" [disabled]="form.controls.duration.value != 1">
|
||||||
|
</ion-datetime>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
<ion-item button (click)="selectDuration('2')">
|
<ion-item button (click)="selectDuration('2')">
|
||||||
<ion-radio slot="end" value="2"></ion-radio>
|
<ion-radio slot="end" value="2"></ion-radio>
|
||||||
|
|
|
@ -75,6 +75,8 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
|
||||||
eventRepeatId?: number;
|
eventRepeatId?: number;
|
||||||
otherEventsCount = 0;
|
otherEventsCount = 0;
|
||||||
eventId?: number;
|
eventId?: number;
|
||||||
|
maxDate: string;
|
||||||
|
minDate: string;
|
||||||
|
|
||||||
// Form variables.
|
// Form variables.
|
||||||
form: FormGroup;
|
form: FormGroup;
|
||||||
|
@ -94,7 +96,6 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
|
||||||
protected fb: FormBuilder,
|
protected fb: FormBuilder,
|
||||||
@Optional() protected svComponent: CoreSplitViewComponent,
|
@Optional() protected svComponent: CoreSplitViewComponent,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.currentSite = CoreSites.getCurrentSite()!;
|
this.currentSite = CoreSites.getCurrentSite()!;
|
||||||
this.errors = {
|
this.errors = {
|
||||||
required: Translate.instant('core.required'),
|
required: Translate.instant('core.required'),
|
||||||
|
@ -122,6 +123,9 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
|
||||||
this.form.addControl('repeat', this.fb.control(false));
|
this.form.addControl('repeat', this.fb.control(false));
|
||||||
this.form.addControl('repeats', this.fb.control('1'));
|
this.form.addControl('repeats', this.fb.control('1'));
|
||||||
this.form.addControl('repeateditall', this.fb.control(1));
|
this.form.addControl('repeateditall', this.fb.control(1));
|
||||||
|
|
||||||
|
this.maxDate = CoreTimeUtils.getDatetimeDefaultMax();
|
||||||
|
this.minDate = CoreTimeUtils.getDatetimeDefaultMin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<span *ngIf="inputMode && form" [formGroup]="form">
|
<span *ngIf="inputMode && form" [formGroup]="form">
|
||||||
<span *ngIf="editMode" [core-mark-required]="field.required" class="core-mark-required"></span>
|
<span *ngIf="editMode" [core-mark-required]="field.required" class="core-mark-required"></span>
|
||||||
<ion-datetime [formControlName]="'f_'+field.id" [placeholder]="'core.date' | translate"
|
<ion-datetime [formControlName]="'f_'+field.id" [placeholder]="'core.date' | translate" [max]="maxDate" [min]="minDate"
|
||||||
[disabled]="searchMode && !searchFields!['f_'+field.id+'_z']" [displayFormat]="format"></ion-datetime>
|
[disabled]="searchMode && !searchFields!['f_'+field.id+'_z']" [displayFormat]="format">
|
||||||
|
</ion-datetime>
|
||||||
<core-input-errors *ngIf="error && editMode" [control]="form.controls['f_'+field.id]" [errorText]="error"></core-input-errors>
|
<core-input-errors *ngIf="error && editMode" [control]="form.controls['f_'+field.id]" [errorText]="error"></core-input-errors>
|
||||||
|
|
||||||
<ion-item *ngIf="searchMode">
|
<ion-item *ngIf="searchMode">
|
||||||
|
|
|
@ -28,6 +28,8 @@ export class AddonModDataFieldDateComponent extends AddonModDataFieldPluginCompo
|
||||||
|
|
||||||
format!: string;
|
format!: string;
|
||||||
displayDate?: number;
|
displayDate?: number;
|
||||||
|
maxDate?: string;
|
||||||
|
minDate?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
|
@ -43,6 +45,8 @@ export class AddonModDataFieldDateComponent extends AddonModDataFieldPluginCompo
|
||||||
this.format = CoreTimeUtils.fixFormatForDatetime(CoreTimeUtils.convertPHPToMoment(
|
this.format = CoreTimeUtils.fixFormatForDatetime(CoreTimeUtils.convertPHPToMoment(
|
||||||
Translate.instant('core.strftimedate'),
|
Translate.instant('core.strftimedate'),
|
||||||
));
|
));
|
||||||
|
this.maxDate = CoreTimeUtils.getDatetimeDefaultMax();
|
||||||
|
this.minDate = CoreTimeUtils.getDatetimeDefaultMin();
|
||||||
|
|
||||||
if (this.searchMode) {
|
if (this.searchMode) {
|
||||||
this.addControl('f_' + this.field.id + '_z');
|
this.addControl('f_' + this.field.id + '_z');
|
||||||
|
|
|
@ -33,8 +33,8 @@ import { CoreLang } from '@services/lang';
|
||||||
export class AddonUserProfileFieldDatetimeComponent extends CoreUserProfileFieldBaseComponent {
|
export class AddonUserProfileFieldDatetimeComponent extends CoreUserProfileFieldBaseComponent {
|
||||||
|
|
||||||
format?: string;
|
format?: string;
|
||||||
min?: number;
|
min?: string;
|
||||||
max?: number;
|
max?: string;
|
||||||
valueNumber = 0;
|
valueNumber = 0;
|
||||||
monthNames?: string[];
|
monthNames?: string[];
|
||||||
|
|
||||||
|
@ -66,20 +66,17 @@ export class AddonUserProfileFieldDatetimeComponent extends CoreUserProfileField
|
||||||
));
|
));
|
||||||
|
|
||||||
// Check min value.
|
// Check min value.
|
||||||
if (field.param1) {
|
if (field.param1 && Number(field.param1)) {
|
||||||
const year = parseInt(field.param1, 10);
|
this.min = field.param1;
|
||||||
if (year) {
|
|
||||||
this.min = year;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check max value.
|
// Check max value.
|
||||||
if (field.param2) {
|
if (field.param2 && Number(field.param2)) {
|
||||||
const year = parseInt(field.param2, 10);
|
this.max = field.param2;
|
||||||
if (year) {
|
|
||||||
this.max = year;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.max = this.max || CoreTimeUtils.getDatetimeDefaultMin();
|
||||||
|
this.max = this.max || CoreTimeUtils.getDatetimeDefaultMax();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -367,6 +367,20 @@ export class CoreTimeUtilsProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default max year for datetime inputs.
|
||||||
|
*/
|
||||||
|
getDatetimeDefaultMax(): string {
|
||||||
|
return String(moment().year() + 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default min year for datetime inputs.
|
||||||
|
*/
|
||||||
|
getDatetimeDefaultMin(): string {
|
||||||
|
return String(moment().year() - 20);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CoreTimeUtils = makeSingleton(CoreTimeUtilsProvider);
|
export const CoreTimeUtils = makeSingleton(CoreTimeUtilsProvider);
|
||||||
|
|
Loading…
Reference in New Issue