Current date in field

Hello! How to put the current date in a date type field?

Datasource. getItem.setStartDate (new Date).

Use this in init or initNewItem method.

The field will be updated automatically.

Can give an example? please

Sure.
Give me some time to find the code.
I guess you want to set current date when you
create a new instance.

I don’t have a full example but. I have a snippet here:
In the AbstractEditor class overwrite the initNewItem method:
inject the datasource like this in the class


public class AssignmentEdit extends AbstractEditor<Assignment> {
      @Inject
       private Datasource<Assignment> assignmentDs;

       @Override 
        protected void initNewItem(Assignment item) {
               assignment.setAssignmentStartDate(new Date());
               assignment.setAssignmentEndDate(new Date());
        }
}

That’s it. The Date field should now be filled with current Date, when created first time.

1 Like

Thank you so much!!!