Skip to content

Commit

Permalink
fix datetimepicker form bugs, add form example (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikerodonnell89 committed Jun 26, 2019
1 parent 31addcd commit 966723f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
Expand Up @@ -49,3 +49,11 @@ <h2>Formatting</h2>
</component-example>
<code-example [code]="datetimeFormatHtml" [language]="'HTML'"></code-example>
<code-example [code]="datetimeFormatTs" [language]="'typescript'"></code-example>

<separator></separator>
<h2>Use in a form</h2>
<component-example [name]="'ex5'">
<fd-datetime-form-example></fd-datetime-form-example>
</component-example>
<code-example [code]="datetimeFormHtml" [language]="'HTML'"></code-example>
<code-example [code]="datetimeFormTs" [language]="'typescript'"></code-example>
Expand Up @@ -14,6 +14,9 @@ import * as dateTimePickerAllowNullTs from '!raw-loader!./examples/datetime-allo
import * as dateTimeFormatHtml from '!raw-loader!./examples/datetime-format-example/datetime-format-example.component.html';
import * as dateTimeFormatTs from '!raw-loader!./examples/datetime-format-example/datetime-format-example.component.ts';

import * as dateTimeFormHtml from '!raw-loader!./examples/datetime-form-example/datetime-form-example.component.html';
import * as dateTimeFormTs from '!raw-loader!./examples/datetime-form-example/datetime-form-example.component.ts';


@Component({
selector: 'app-datetime-picker-docs',
Expand All @@ -34,6 +37,9 @@ export class DatetimePickerDocsComponent {
datetimeFormatHtml = dateTimeFormatHtml;
datetimeFormatTs = dateTimeFormatTs;

datetimeFormHtml = dateTimeFormHtml;
datetimeFormTs = dateTimeFormTs;

datetimePickerAllowNullTs = dateTimePickerAllowNullTs;

}
@@ -0,0 +1,8 @@
<form [formGroup]="customForm">
<fd-datetime-picker formControlName="date"></fd-datetime-picker>
</form>

Touched: {{customForm.controls.date.touched}}<br/>
Dirty: {{customForm.controls.date.dirty}}<br/>

Selected Date: {{ customForm.controls.date.value ? customForm.controls.date.value.toDateString() : 'null' }}
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';

@Component({
selector: 'fd-datetime-form-example',
templateUrl: './datetime-form-example.component.html'
})
export class DatetimeFormExampleComponent {
customForm = new FormGroup({
date: new FormControl(new Date())
});
}
2 changes: 2 additions & 0 deletions docs/app/documentation/documentation.module.ts
Expand Up @@ -324,6 +324,7 @@ import { DatePickerPositionExampleComponent } from './component-docs/date-picker
import { TimePickerOtherDelimiterExampleComponent } from './component-docs/time-picker/examples/time-picker-other-delimiter-example.component';
import { DatetimeFormatExampleComponent } from './component-docs/datetime-picker/examples/datetime-format-example/datetime-format-example.component';
import { HighlightModule } from 'ngx-highlightjs';
import { DatetimeFormExampleComponent } from './component-docs/datetime-picker/examples/datetime-form-example/datetime-form-example.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -410,6 +411,7 @@ import { HighlightModule } from 'ngx-highlightjs';
DatetimeNonMeridianExampleComponent,
DatetimeProgramExampleComponent,
DatetimeFormatExampleComponent,
DatetimeFormExampleComponent,
DatetimePickerAllowNullExampleComponent,
DropdownContextualMenuExampleComponent,
DropdownDefaultExampleComponent,
Expand Down
2 changes: 2 additions & 0 deletions library/src/lib/datetime-picker/datetime-picker.component.ts
Expand Up @@ -177,6 +177,7 @@ export class DatetimePickerComponent implements OnInit, OnDestroy, ControlValueA

/** Toggles the popover. */
togglePopover(): void {
this.onTouched(this.selectedDay.date);
if (this.isOpen) {
this.closePopover();
} else {
Expand All @@ -186,6 +187,7 @@ export class DatetimePickerComponent implements OnInit, OnDestroy, ControlValueA

/** Opens the popover. */
openPopover(inputFieldDate?: string): void {
this.onTouched(this.selectedDay.date);
if (!this.isOpen) {
this.isOpen = true;
if (inputFieldDate !== null && inputFieldDate !== '' && !this.isInvalidDateInput) {
Expand Down

0 comments on commit 966723f

Please sign in to comment.