Fill in default date when editing existing record

Hello again. I have another Polymer problem that seems simple on the surface, but I’m not sure how to do it. I have an entity loaded in the form, but it has a blank date field, which I would like to fill with the current date when the page loads.

The field definition looks like this:

<paper-input value="{{entity.actualCompletionDate}}"
             invalid="[[_isInvalid(serverErrors.actualCompletionDate)]]" >

So what I’d like to do is fill in the entity.actualCompletionDate with today’s date (without the user having to select it themselves).

How do I do that?

Hi, you can achieve it using observer:

class MyComponent {

        static get observers() {
          return [

        _setupEntity(entity) {
          if (this.entity && !this.entity.actualCompletionDate) {
            this.entity.actualCompletionDate = (new Date()).toISOString();

Ah! Thank you very much for that. I can see I was on the wrong track.

I tried putting the date picker back into the HTML, and this solution couldn’t cope with it unfortunately. But that’s not a problem. I think this has given me enough to go on.

And another observation: it seems that Cuba is generating a mix of Polymer 1.0 and Polymer 2.0 code. The Cuba components are Polymer 1.0 by the looks of it.

Thanks again.

Currently studio generates components using Polymer 2.0 syntax. Cuba components remain in Polymer 1.0 since it’s compatible with Polymer 2.0 in hybrid mode, but they will be rewritten as mixins soon.