-
Notifications
You must be signed in to change notification settings - Fork 4
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
Closed
fix: Handle invalid input in TimeFieldMinMax, resolve missing CSS reference, and remove classnames #110
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dda24b6
fix: Handle invalid input in TimeField and resolve missing CSS reference
laurenic0l 4eca806
fix: removed class name
laurenic0l 5759035
fix: update TimeFieldMinMaxView to improve validation and feedback
laurenic0l 2b14eff
fix: replace onModify with onValueChange
laurenic0l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 33 additions & 26 deletions
59
src/main/java/com/webforj/samples/views/fields/timefield/TimeFieldMinMaxView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
|
||
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ?!
There was a problem hiding this comment.
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