forked from CIT/Vmeda.Online
		
	MOBILE-3722 core: Set default min and max for datetimes
This commit is contained in:
		
							parent
							
								
									6a846488ee
								
							
						
					
					
						commit
						c2bcf91049
					
				@ -32,7 +32,8 @@
 | 
			
		||||
                        {{ 'core.date' | translate }}
 | 
			
		||||
                    </h2>
 | 
			
		||||
                </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>
 | 
			
		||||
                <core-input-errors item-content [control]="form.controls.timestart" [errorMessages]="errors"></core-input-errors>
 | 
			
		||||
            </ion-item>
 | 
			
		||||
@ -164,9 +165,10 @@
 | 
			
		||||
                        <ion-item  (click)="selectDuration('1')">
 | 
			
		||||
                            <ion-radio slot="end" value="1"></ion-radio>
 | 
			
		||||
                            <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"
 | 
			
		||||
                                [displayFormat]="dateFormat" [disabled]="form.controls.duration.value != 1"></ion-datetime>
 | 
			
		||||
                                [displayFormat]="dateFormat" [disabled]="form.controls.duration.value != 1">
 | 
			
		||||
                            </ion-datetime>
 | 
			
		||||
                        </ion-item>
 | 
			
		||||
                        <ion-item (click)="selectDuration('2')">
 | 
			
		||||
                            <ion-radio slot="end" value="2"></ion-radio>
 | 
			
		||||
 | 
			
		||||
@ -75,6 +75,8 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
 | 
			
		||||
    eventRepeatId?: number;
 | 
			
		||||
    otherEventsCount = 0;
 | 
			
		||||
    eventId?: number;
 | 
			
		||||
    maxDate: string;
 | 
			
		||||
    minDate: string;
 | 
			
		||||
 | 
			
		||||
    // Form variables.
 | 
			
		||||
    form: FormGroup;
 | 
			
		||||
@ -94,7 +96,6 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
 | 
			
		||||
        protected fb: FormBuilder,
 | 
			
		||||
        @Optional() protected svComponent: CoreSplitViewComponent,
 | 
			
		||||
    ) {
 | 
			
		||||
 | 
			
		||||
        this.currentSite = CoreSites.getCurrentSite()!;
 | 
			
		||||
        this.errors = {
 | 
			
		||||
            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('repeats', 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="editMode" [core-mark-required]="field.required" class="core-mark-required"></span>
 | 
			
		||||
    <ion-datetime [formControlName]="'f_'+field.id" [placeholder]="'core.date' | translate"
 | 
			
		||||
        [disabled]="searchMode && !searchFields!['f_'+field.id+'_z']" [displayFormat]="format"></ion-datetime>
 | 
			
		||||
    <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>
 | 
			
		||||
    <core-input-errors *ngIf="error && editMode" [control]="form.controls['f_'+field.id]" [errorText]="error"></core-input-errors>
 | 
			
		||||
 | 
			
		||||
    <ion-item *ngIf="searchMode">
 | 
			
		||||
 | 
			
		||||
@ -28,6 +28,8 @@ export class AddonModDataFieldDateComponent extends AddonModDataFieldPluginCompo
 | 
			
		||||
 | 
			
		||||
    format!: string;
 | 
			
		||||
    displayDate?: number;
 | 
			
		||||
    maxDate?: string;
 | 
			
		||||
    minDate?: string;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @inheritdoc
 | 
			
		||||
@ -43,6 +45,8 @@ export class AddonModDataFieldDateComponent extends AddonModDataFieldPluginCompo
 | 
			
		||||
        this.format = CoreTimeUtils.fixFormatForDatetime(CoreTimeUtils.convertPHPToMoment(
 | 
			
		||||
            Translate.instant('core.strftimedate'),
 | 
			
		||||
        ));
 | 
			
		||||
        this.maxDate = CoreTimeUtils.getDatetimeDefaultMax();
 | 
			
		||||
        this.minDate = CoreTimeUtils.getDatetimeDefaultMin();
 | 
			
		||||
 | 
			
		||||
        if (this.searchMode) {
 | 
			
		||||
            this.addControl('f_' + this.field.id + '_z');
 | 
			
		||||
 | 
			
		||||
@ -33,8 +33,8 @@ import { CoreLang } from '@services/lang';
 | 
			
		||||
export class AddonUserProfileFieldDatetimeComponent extends CoreUserProfileFieldBaseComponent {
 | 
			
		||||
 | 
			
		||||
    format?: string;
 | 
			
		||||
    min?: number;
 | 
			
		||||
    max?: number;
 | 
			
		||||
    min?: string;
 | 
			
		||||
    max?: string;
 | 
			
		||||
    valueNumber = 0;
 | 
			
		||||
    monthNames?: string[];
 | 
			
		||||
 | 
			
		||||
@ -66,20 +66,17 @@ export class AddonUserProfileFieldDatetimeComponent extends CoreUserProfileField
 | 
			
		||||
        ));
 | 
			
		||||
 | 
			
		||||
        // Check min value.
 | 
			
		||||
        if (field.param1) {
 | 
			
		||||
            const year = parseInt(field.param1, 10);
 | 
			
		||||
            if (year) {
 | 
			
		||||
                this.min = year;
 | 
			
		||||
            }
 | 
			
		||||
        if (field.param1 && Number(field.param1)) {
 | 
			
		||||
            this.min = field.param1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Check max value.
 | 
			
		||||
        if (field.param2) {
 | 
			
		||||
            const year = parseInt(field.param2, 10);
 | 
			
		||||
            if (year) {
 | 
			
		||||
                this.max = year;
 | 
			
		||||
            }
 | 
			
		||||
        if (field.param2 && Number(field.param2)) {
 | 
			
		||||
            this.max = field.param2;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user