Date field initializer

Hi there! In my project I have next problem: it is very often to need set current time to datefield component. I can do that on after init event, but I want to do that by the button inside component (like ‘calendar’ button). Also I want to add ‘clear’ button.

Is it any ways to get solution? Can I change xml-descriptor schema and configure actions in xml-descriptor (like in lookupField as example)?

Can I change DateFieldImpl or JmixDateField, and if I can, what is best way to do that?

Hello Igor,

you can override DateField component and register your own implementation. Could you clarify do you use Jmix application? Because we provide another way of overriding components than CUBA.

How to override UI component in CUBA you can see these topics:

Hi Roman, thank you for rapid answer! My current project is Jmix application, but sometimes I use CUBA app.

I tried to extends DateField component, but I think there is exists better solution. Could you please describe steps I should do to solve my problem? I don’t know where and how add new button inside component.

I’d like to use code like this one:

ExtDateField dateField = uiComponents.create(ExtDateField.NAME);
dateField.getClearAction(); // return clear action
dateField.getCurrentTimeAction(true); // return current time action

and

<dateField id="extDateField">
<actions>
    <action id="clear"/>
    <action id="currentTime"/>
</actions>

image

I see, yes better do not extend the DateField component but create CompositeComponent. You can read about it in the documentation 3.5.14. Composite Components article.

In this case, the composite component should contain DateField and Button. To show them as one component application should extend the theme and add some CSS styles.

You can follow the article above but to register component you should do the following:

@SpringBootApplication
public class FdateApplication {
    public static void main(String[] args) {
        SpringApplication.run(FdateApplication.class, args);
    }

   ...

    @Bean
    public ComponentRegistration customDateField() {
        return ComponentRegistrationBuilder.create("customDateField")
                .withComponentClass(CustomDateField.class)
                .withComponentLoaderClass(CustomDateFieldLoader.class)
                .build();
    }
}

More details in the demo project: demo.zip (87.6 KB)

Thank you so much! I’ll see demo project and will try this way. I think it will help me/