Field filled with today’s date on view startup

Asked

Viewed 19 times

0

Hello,

I wanted to put today’s pre-set date in a date field on view startup.

I tried so:

Component:

this.MeuForm = this.fb.group({
  dataInicio: [{date: {year: (new Date()).getFullYear(), month: (new Date()).getMonth() + 1, day: (new Date()).getDate()}}],
  dataFim: ''
});

<div class="col-md-2">
  <div class="form-group">
      <label class="control-label" for="dataInicio">Data Inicial</label>
      <dx-date-box type="date" width="100%" displayFormat="dd/MM/yyyy"
          formControlName="dataInicio"></dx-date-box>
  </div>
</div>
<div class="col-md-2">
  <div class="form-group">
      <label class="control-label" for="dataFim">Data Final</label>
      <dx-date-box type="date" width="100%" displayFormat="dd/MM/yyyy"
          formControlName="dataFim"></dx-date-box>
  </div>
</div>

Upshot:

inserir a descrição da imagem aqui

It turns out that, first, there is no date today and second, I no longer have the icon there to choose another date.

  • 1

    dataFim: new Date(), take a look at the documentation of your library what kind of data it expects.

  • worked, thanks

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.