Skip to content

Commit

Permalink
Fix datetime input bug (#999)
Browse files Browse the repository at this point in the history
* fix: repair datetime input bug

* fix: remove unnecessary data
  • Loading branch information
jeanmurillo95 authored Jul 11, 2023
1 parent deb613d commit 8851a1c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<ngx-input
type="datetime-local"
[ngModel]="model"
(ngModelChange)="updateModel($event)"
(ngModelChange)="updateDateTime($event)"
[requiredIndicator]="false"
[required]="required"
[disabled]="isDuplicated"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
OnDestroy
} from '@angular/core';
import { JsonEditorNode } from '../../json-editor-node';
import { DateFormatPipe } from 'ngx-moment';

import { DialogService } from '../../../dialog/dialog.service';
import { JSONEditorSchema, JSONEditorTemplateProperty, JsonSchemaDataType } from '../../json-editor.helper';
Expand All @@ -23,6 +24,7 @@ import { JSONSchema7TypeName } from 'json-schema';
selector: 'ngx-json-editor-node-flat',
templateUrl: './json-editor-node-flat.component.html',
styleUrls: ['./json-editor-node-flat.component.scss'],
providers: [DateFormatPipe],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
})
Expand Down Expand Up @@ -71,7 +73,7 @@ export class JsonEditorNodeFlatComponent extends JsonEditorNode implements OnIni
nodeExpandTrigger$ = new Subject<boolean>();
private readonly unsub$: Subject<void> = new Subject();

constructor(public dialogMngr: DialogService) {
constructor(public dialogMngr: DialogService, private dateFormat: DateFormatPipe) {
super(dialogMngr);
}

Expand Down Expand Up @@ -112,4 +114,8 @@ export class JsonEditorNodeFlatComponent extends JsonEditorNode implements OnIni
this.expanded = value;
}
}

updateDateTime(value: any): void {
this.updateDateTimeModel(value, this.dateFormat);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
import { createValueForSchema, inferType, JSONEditorSchema } from './json-editor.helper';
import { DialogComponent } from '../dialog/dialog.component';
import { DialogService } from '../dialog/dialog.service';
import { DateFormatPipe } from 'ngx-moment';

const DATETIME_FORMAT = 'YYYY-MM-DD[T]HH:mm:ss';

@Directive()
export class JsonEditorNode implements OnInit, OnChanges {
Expand Down Expand Up @@ -177,6 +180,10 @@ export class JsonEditorNode implements OnInit, OnChanges {
this.modelChange.emit(this.model);
}

updateDateTimeModel(value: any, format: DateFormatPipe): void {
this.updateModel(format.transform(value, DATETIME_FORMAT));
}

/**
* Expand click event
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
[placeholder]="placeholder"
[ngModel]="model"
[disabled]="isDuplicated"
(ngModelChange)="updateModel($event)"
(ngModelChange)="updateDateTime($event)"
[required]="required"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { JsonEditorNode } from '../../json-editor-node';

import { DialogService } from '../../../dialog/dialog.service';
import { JSONEditorSchema } from '../../json-editor.helper';
import { DateFormatPipe } from 'ngx-moment';

@Component({
selector: 'ngx-json-editor-node',
templateUrl: 'json-editor-node.component.html',
styleUrls: ['./json-editor-node.component.scss'],
providers: [DateFormatPipe],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
})
Expand All @@ -28,7 +30,7 @@ export class JsonEditorNodeComponent extends JsonEditorNode implements OnInit {

placeholder = '';

constructor(public dialogMngr: DialogService) {
constructor(public dialogMngr: DialogService, private dateFormat: DateFormatPipe) {
super(dialogMngr);
}

Expand All @@ -39,4 +41,8 @@ export class JsonEditorNodeComponent extends JsonEditorNode implements OnInit {
this.placeholder = this.schema.examples.join(', ');
}
}

updateDateTime(value: any): void {
this.updateDateTimeModel(value, this.dateFormat);
}
}

0 comments on commit 8851a1c

Please sign in to comment.