[Vuejs]-Vuejs: Insert date today in input

1👍

You can update the model value form.debarred on page load like:

this.form.debarred = new Date().toLocaleDateString('en-CA');
//==> "2020-04-03" 

Now, using .toLocaleDateString('en-CA') is need here as <input type="date"> value can only accept a string representing a date in YYYY-MM-DD format, or empty.

DEMO:

const debarred = document.querySelector('[name=debarred]');
debarred.value = new Date().toLocaleDateString('en-CA');
<div class="form-group">
  <label>Debarred</label>
  <input type="date" name="debarred" placeholder="Debarred" class="form-control">
  <has-error :form="form" field="debarred"></has-error>
</div>

Leave a comment