import moment from "moment" ; import { InputFieldsComponentsDef } from "@xgovformbuilder/model" ; import * as helpers from "./helpers" ; import { FormComponent } from "./FormComponent" ; import { FormData , FormSubmissionErrors , FormSubmissionState } from "../types" ; import { FormModel } from "../models" ; import { addClassOptionIfNone } from "./helpers" ; export class DateTimeField extends FormComponent { constructor ( def , model ) { super ( def , model ) ; addClassOptionIfNone ( this . options , "govuk-input--width-20" ) ; } getFormSchemaKeys ( ) { return helpers . getFormSchemaKeys ( this . name , "date" , this ) ; } getStateSchemaKeys ( ) { return helpers . getStateSchemaKeys ( this . name , "date" , this ) ; } getFormValueFromState ( state ) { const name = this . name ; const value = state [ name ] ; return value ? moment ( value ) . format ( "YYYY-MM-DDTHH:mm" ) : value ; } getDisplayStringFromState ( state ) { const name = this . name ; const value = state [ name ] ; return value ? moment ( value ) . format ( "D MMMM YYYY h:mma" ) : "" ; } getViewModel ( formData , errors ) { return { ... super . getViewModel ( formData , errors ) , type : "datetime-local" , } ; } }