File

packages/ui/src/lib/form/datetime/datetime.component.ts

Description

Input for a datetime.

https://components.entrecode.de/ui/datetime?e=1

Implements

ControlValueAccessor

Metadata

providers { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => DatetimeComponent), multi: true, }
selector ec-datetime
templateUrl datetime.component.html

Index

Properties
Methods
Inputs

Inputs

date
Type : moment.Moment

The date that should be displayed at start.

dateOnly
Default value : false

If true, the time will not be in the emitted value

disableTime
Type : boolean

If true, the time will not be displayed nor will be editable.

formControl
Type : FormControl
Default value : new FormControl()

The form control that holds the date

placeholder
Default value : ''

The input's placeholder

Methods

registerOnChange
registerOnChange(fn)

registerOnChange implementation of ControlValueAccessor

Parameters :
Name Optional
fn No
Returns : void
registerOnTouched
registerOnTouched()

registerOnTouched implementation of ControlValueAccessor

Returns : void
setDisabledState
setDisabledState(isDisabled)
Parameters :
Name Optional
isDisabled No
Returns : void
writeValue
writeValue(value: Date)

Selects the given Date when the model changes.

Parameters :
Name Type Optional
value Date No
Returns : void

Properties

calendar
Type : CalendarComponent
Decorators :
@ViewChild(CalendarComponent, {static: true})

The used calendar component

disabled
Type : boolean

If true, the time cannot be changed

propagateChange
Default value : () => {...}

Change propagation for ControlValueAccessor

Public weekdays
Type : string[]

Array of the days of a week.

import { Component, forwardRef, Input, ViewChild } from '@angular/core';
import { ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR } from '@angular/forms';
import { CalendarComponent } from '@ec.components/calendar';
import moment from 'moment-es6';

/** Input for a datetime.
 *
 * <example-url>https://components.entrecode.de/ui/datetime?e=1</example-url>
 *
 */
@Component({
  selector: 'ec-datetime',
  templateUrl: 'datetime.component.html',
  providers: [
    {
      provide: NG_VALUE_ACCESSOR,
      useExisting: forwardRef(() => DatetimeComponent),
      multi: true,
    },
  ],
})
export class DatetimeComponent implements ControlValueAccessor {
  /** The date that should be displayed at start. */
  @Input() date: moment.Moment;
  /** The form control that holds the date */
  @Input() formControl: FormControl = new FormControl();
  /** The used calendar component */
  @ViewChild(CalendarComponent, { static: true }) calendar: CalendarComponent;
  /** Array of the days of a week. */
  public weekdays: string[];
  /** If true, the time will not be displayed nor will be editable. */
  @Input() disableTime: boolean;
  /** If true, the time will not be in the emitted value */
  @Input() dateOnly = false;
  /** The input's placeholder */
  @Input() placeholder = '';
  /** If true, the time cannot be changed */
  disabled: boolean;

  /** Selects the given Date when the model changes. */
  writeValue(value: Date) {
    this.calendar.writeValue(value);
  }

  /** Change propagation for ControlValueAccessor */
  propagateChange = (_: any) => { };

  /** registerOnChange implementation of ControlValueAccessor */
  registerOnChange(fn) {
    this.propagateChange = fn;
  }

  /** registerOnTouched implementation of ControlValueAccessor */
  registerOnTouched() { }

  setDisabledState(isDisabled) {
    this.disabled = isDisabled;
  }
}
<div class="ec-datetime-picker">
  <div class="input-group">
    <input
      class="input"
      [value]="calendar.inputValue"
      (input)="calendar.input($event.target.value)"
      (focus)="calendarPop.show()"
      (blur)="calendarPop.hide()"
      [placeholder]="placeholder"
      [disabled]="disabled"
    />
    <div class="input-group__addon">
      <a (click)="calendarPop.toggle()">
        <ec-icon name="calendar"></ec-icon>
      </a>
    </div>
  </div>
  <ec-pop class="ec-datetime-select" #calendarPop (mousedown)="$event.preventDefault()">
    <ec-calendar
      #calendar
      [formControl]="formControl"
      [disableTime]="disableTime"
      [dateOnly]="dateOnly"
      [date]="date"
    ></ec-calendar>
  </ec-pop>
</div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""