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

fix: Handle invalid input in TimeFieldMinMax, resolve missing CSS reference, and remove classnames #110

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,51 +1,58 @@
package com.webforj.samples.views.fields.timefield;

import com.webforj.App;
import com.webforj.annotation.InlineStyleSheet;
import com.webforj.component.Composite;
import com.webforj.component.Theme;
import com.webforj.component.button.Button;
import com.webforj.component.button.ButtonTheme;
import com.webforj.component.field.TimeField;
import com.webforj.component.layout.flexlayout.FlexAlignment;
import com.webforj.component.layout.flexlayout.FlexLayout;
import com.webforj.component.layout.flexlayout.FlexWrap;
import com.webforj.component.toast.Toast;
import com.webforj.router.annotation.FrameTitle;
import com.webforj.router.annotation.Route;

import java.time.LocalTime;

@InlineStyleSheet("context://css/fields/timefield/timeFieldMinMaxView.css")
@Route
@FrameTitle("Time Field Min/Max")
public class TimeFieldMinMaxView extends Composite<FlexLayout> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do something useful with the confirm button. A toast ?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented a toast to confirm the action


TimeField meeting = new TimeField(LocalTime.of(12, 30));
Button confirm = new Button("Confirm", ButtonTheme.PRIMARY);
private TimeField meeting = new TimeField();
private Button confirm = new Button("Confirm", ButtonTheme.PRIMARY);

public TimeFieldMinMaxView() {
getBoundComponent().setWrap(FlexWrap.WRAP)
.setSpacing("var(--dwc-space-l")
getBoundComponent()
.setWrap(FlexWrap.WRAP)
.setSpacing("var(--dwc-space-l)")
.setMargin("var(--dwc-space-m)");

meeting.setWidth("250px");
confirm.setWidth("150px");

getBoundComponent().add(meeting, confirm);

getBoundComponent().setItemAlignment(FlexAlignment.END, confirm);

LocalTime min = LocalTime.of(12, 30);
LocalTime max = LocalTime.of(17, 15);
String label = "Choose a meeting time between %s and %s:".formatted(min, max);
meeting.setMin(min)
.setMax(max);

meeting.setLabel(label)
.onModify(e -> {
try {
meeting.setText(e.getText());
confirm.setEnabled(true);
} catch (IllegalArgumentException ex) {
confirm.setEnabled(false);
}
App.console().log(meeting.getValue() + "");
});
meeting.setLabel("Choose a meeting time:");
confirm.setEnabled(false);

meeting.onValueChange(event -> {
LocalTime selectedTime = event.getValue();
confirm.setEnabled(selectedTime != null);
});

confirm.onClick(e -> {
if (meeting.getValue() != null) {
showToast("Meeting time confirmed!");
} else {
showToast("Invalid time selected!");
}
});
}

private void showToast(String message) {
Toast toast = new Toast(message);
toast.setDuration(3000);
toast.setTheme(Theme.SUCCESS);
toast.open();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public class TimeFieldView extends Composite<FlexLayout> {
public TimeFieldView() {
getBoundComponent().setMargin("var(--dwc-space-m)");

reminder.addClassName("date__input");

getBoundComponent().add(reminder);
}

Expand Down