Search code examples
htmlangularjstypescriptjhipsterjhipster-registry

Set Value of form field as current date in JHipster


We are trying to set default value of form field as current date in Jhipster.

Now, jhipster provides a moment format to a date which is eventually a ngbdatepicker. If we try to change the input type to "date" we cannot assign moment instance with date. If we typecast new date object as moment, the template shows error messages.

Please let us know if its possible.

Thanks in advance.


Solution

  • I have found a way around to solve this problem:

    All you need to do is typecast your standard date object to moment after importing the moment obviously:

    import * as moment from 'moment';

    and typecast your field something like

    your_form_field = moment(new Date());

    Eg: this.mstSite.siteUpdatedOn = moment(new Date());

    Hope this solves your problems.

    ...Cheers...