Skip to content

Picker: default value is incorrectly set as new value when user taps Cancel (only on first use) #5014

@ThomasH99

Description

@ThomasH99

In 7.0.244, the new support for setting the datePicker.setDefaultDate() has created a side-effect:

Run the code below, the picker will show "..." (no value set), tap the picker, it will show current time (the expected default value), then click Cancel and the displayed picker time will incorrectly be current time (where it should still be "..."). Clicking the button "Print Picker GetDate()" confirms the Picker returns the default value despite the Cancel.

This only happens on the initial use. If you click the picker a second time, update the value, and then tap Cancel, the old value is kept as expected.

                Form form = new Form("Test Picker", new BoxLayout(BoxLayout.Y_AXIS));
                Picker datePicker = new Picker();
                datePicker.setDefaultDate(()->new Date());
                datePicker.setType(Display.PICKER_TYPE_DATE);
                datePicker.setDate(null);
                form.add(datePicker);
                Button but = new Button(Command.createMaterial("Print Picker GetDate()", FontImage.MATERIAL_FLASH_ON,
                        e -> Log.p(datePicker.getDate().toString())));
                form.add(but);
                form.show();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions