Skip to content

Commit

Permalink
Added strict mode to avoid inserting more chars than the mask
Browse files Browse the repository at this point in the history
  • Loading branch information
gldiazcardenas committed Oct 25, 2023
1 parent e0db1b0 commit 351d8f0
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ public class PhoneNumberFieldApp extends Application {
@Override
public void start(Stage stage) throws Exception {
PhoneNumberField field = new PhoneNumberField();
field.setPhoneNumber("573003767182");

VBox controls = new VBox(10);
addControl("Available Countries", availableCountriesSelector(field), controls);
addControl("Preferred Countries", preferredCountriesSelector(field), controls);
addControl("Default Country", defaultCountrySelector(field), controls);
addControl("Disable Country", disableCountryCheck(field), controls);
addControl("Force Local Phone", forceLocalPhoneNumberCheck(field), controls);
addControl("Strict Mode", strictModeCheck(field), controls);
addControl("Unmasked", unmaskedModeCheck(field), controls);

VBox fields = new VBox(10);
addField(fields, "Country Code", field.countryCallingCodeProperty(), COUNTRY_CODE_CONVERTER);
Expand All @@ -56,7 +57,7 @@ public void start(Stage stage) throws Exception {
vBox.getChildren().addAll(controls, new Separator(), field, new Separator(), fields);

stage.setTitle("PhoneNumberField");
stage.setScene(new Scene(vBox, 500, 450));
stage.setScene(new Scene(vBox, 500, 500));
stage.sizeToScene();
stage.centerOnScreen();
stage.show();
Expand Down Expand Up @@ -106,15 +107,33 @@ private Node defaultCountrySelector(PhoneNumberField view) {
}

private Node disableCountryCheck(PhoneNumberField field) {
CheckBox localCheck = new CheckBox();
localCheck.selectedProperty().bindBidirectional(field.disableCountryCodeProperty());
return localCheck;
CheckBox check = new CheckBox();
check.selectedProperty().bindBidirectional(field.disableCountryCodeProperty());
return check;
}

private Node forceLocalPhoneNumberCheck(PhoneNumberField field) {
CheckBox localCheck = new CheckBox();
localCheck.selectedProperty().bindBidirectional(field.forceLocalNumberProperty());
return localCheck;
CheckBox check = new CheckBox();
check.selectedProperty().bindBidirectional(field.forceLocalNumberProperty());
return check;
}

private Node strictModeCheck(PhoneNumberField field) {
CheckBox check = new CheckBox();
check.selectedProperty().bindBidirectional(field.strictModeProperty());
return check;
}

private Node unmaskedModeCheck(PhoneNumberField field) {
CheckBox check = new CheckBox();
check.selectedProperty().addListener((obs, oldV, newV) -> {
if (newV) {
field.setMaskProvider(null);
} else {
field.setMaskProvider(PhoneNumberField.DEFAULT_MASK_PROVIDER);
}
});
return check;
}

private void addControl(String name, Node control, VBox controls) {
Expand Down
Loading

0 comments on commit 351d8f0

Please sign in to comment.