Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateBox should close the popup when cleared and call change listeners when value is null #954

Closed
howudodat opened this issue Aug 17, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@howudodat
Copy link

Create a way to clear a datebox

DateBox.clear() doesn't close the calendar popup
DateBox.setData(null) doesn't call any of the change handlers

As a user I should be able to clear a date selection...

public class NowDateBox extends DateBox {

	public static NowDateBox create() {
		return new NowDateBox();
	}

	public static NowDateBox create(String label) {
		return new NowDateBox(label, new Date(), new CalendarInitConfig());
	}

	public NowDateBox() {
		super();
		addNow();
	}

	public NowDateBox(String label) {
		super(label);
		addNow();
	}

	public NowDateBox(String label, Date date, CalendarInitConfig calendarInitConfig) {
		super(label, date, calendarInitConfig);
		addNow();
	}

	protected void addNow() {
		this.withCalendar((db, cal) -> cal.withFooter((calendar, footer) -> footer.addCss(dui_flex, dui_justify_center)
			.appendChild(Button.create(Icons.calendar_today(), "TODAY")
				.addClickListener(evt -> calendar.setDate(new Date())))
			.appendChild(Button.create(Icons.calendar_today(), "CLEAR")
				.addClickListener(evt -> 
				{
					clear();
				})))

		);
	}


@howudodat
Copy link
Author

howudodat commented Aug 17, 2024

ok, scratch most of that, I was forgetting that I could call setValue on the DateBox to clear it out. However setDate(null) is still an issue. Here is working code for the Clear button:

	protected void addNow() {
		this.withCalendar((db, cal) -> cal.withFooter((calendar, footer) -> footer.addCss(dui_flex, dui_justify_center)
			.appendChild(Button.create(Icons.calendar_today(), "TODAY")
				.addClickListener(evt -> calendar.setDate(new Date())))
			.appendChild(Button.create(Icons.calendar_today(), "CLEAR")
				.addClickListener(evt -> 
				{
					close();
					setValue(null);
				})))

		);
	}

@vegegoku vegegoku self-assigned this Aug 18, 2024
@vegegoku vegegoku added the enhancement New feature or request label Aug 18, 2024
@vegegoku vegegoku added this to the 2.0.3 milestone Aug 18, 2024
@github-project-automation github-project-automation bot moved this to To do in Domino UI Aug 29, 2024
@vegegoku
Copy link
Member

We dont have a setDate(...) function for the DateBox and there is no setValue(..) for the calendar, the DateBox is a form field and uses the setValue, I fixed so it now clears and call change listeners when the value is null and will also close the calendar popup. as for the calendar it will always have a Date and by default clearing the calendar will set it to the specified default date.

so now you can just call clear or setValue null on the DateBox.

@vegegoku vegegoku changed the title V2 DateBox suggestions DateBox should close the popup when cleared and call change listeners when value is null Sep 22, 2024
vegegoku added a commit that referenced this issue Sep 22, 2024
@github-project-automation github-project-automation bot moved this from To do to Done in Domino UI Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

2 participants