Single Selection Type Fields Not Persisting
See original GitHub issueI just started using FormsFX and it’s been great so far. I was able to create a form with string, integer, and boolean type fields and them update a model via properties with no issues. I run into a problem though, when I try to add a single selection type field. The following are the snippets of code showing what I did (I basically followed what’s in the demo application):
private final ListProperty<Integer> allServings =
new SimpleListProperty<>(FXCollections.observableArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
private final ObjectProperty<Integer> serving = new SimpleObjectProperty<>(1);
/**
* References the <code>Form</code> that is bound to this <code>Recipe</code>.
*
* @since 1.0.0
*/
private Form formInstance;
/**
* Retrieves or creates an instance of a FormFX form using the given <code>Recipe</code>.
*
* @return An instance of a FormFX form using the given <code>Recipe</code>.
*
* @since 1.0.0
*/
public Form getOrCreateFormInstance() {
if (Objects.isNull(this.formInstance)) {
createForm();
}
return this.formInstance;
}
/**
* Helper method to initialize the FormFX form field of this <code>Recipe</code>.
*
* @since 1.0.0
*/
private void createForm() {
this.formInstance = Form.of(Group.of(
Field.ofStringType(titleProperty())
.label("Title")
.placeholder("e.g. Chicken Wings")
.required("A title is required for all recipes."),
Field.ofStringType(descriptionProperty())
.label("Description")
.placeholder("e.g. Delicious Honey BBQ wings")
.required("A description is required for all recipes."),
Field.ofIntegerType(caloriesProperty())
.label("Calories")
.placeholder("e.g. 500")
.span(ColSpan.HALF)
.required("The number of calories is required for all recipes."),
Field.ofIntegerType(cookTimeProperty())
.label("Cooking Time")
.placeholder("e.g. 60")
.span(ColSpan.HALF)
.required("The total cooking time (in minutes) is required for all recipes."),
Field.ofSingleSelectionType(allServingsProperty(), servingProperty())
.label("Serving Size")
.placeholder("Serving Size")
.required("The serving size is required for all recipes."),
Field.ofStringType(directionsProperty())
.label("Cooking Directions")
.placeholder("e.g. Bake at 375 degrees in the over for an hour and a half.")
.required("Cooking directions are required for all recipes."),
Field.ofBooleanType(publishedProperty())
.label("Publish Recipe")))
.title("Recipe Form");
}
public Integer getServing() {
return serving.get();
}
public void setServing(Integer serving) {
this.serving.set(serving);
}
public ObjectProperty<Integer> servingProperty() {
return serving;
}
public ObservableList<Integer> getAllServings() {
return allServings.get();
}
public void setAllServings(ObservableList<Integer> allServings) {
this.allServings.set(allServings);
}
public ListProperty<Integer> allServingsProperty() {
return allServings;
}
Here is the method that I use to save the form fields to the database:
@FXML
public void save(ActionEvent event) {
this.recipe.getOrCreateFormInstance().persist();
if (!this.recipe.getOrCreateFormInstance().isValid()) {
return;
}
if (this.recipe.getId() == 0) {
saveRecipe(this.recipe);
}
else {
updateRecipe(this.recipe);
}
}
All other form fields save except the serving field. Am I doing anything incorrectly based on the code I’ve shared? Please let me know if you need anymore context.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Single Selection Type Fields Not Persisting · Issue #2 - GitHub
I was able to create a form with string, integer, and boolean type fields and them update a model via properties with no...
Read more >Entries in Jotform Table not saving - single selection field type
I have a Table set up for one of my forms, essentially acting as my database. I have several columns in my table...
Read more >"SELECT SINGLE" is not working. - SAP Community
Hi all, here i have one report. And in this i want just one row when my input material number match with my...
Read more >Form not posting one field - php - Stack Overflow
I ran into a problem in my php/html code here, and I can't seem to locate the bug. The form seems to be...
Read more >Conditional Formula on Choice Fields (single select) Not ...
Greetings, I have a Modern SharePoint list, using conditional formulas on several text fields that evaluate properly, however, when I use conditional.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It will be available on Maven once I deployed a new release 😃 Hope to find some time for that today.
@martinfrancois Thanks for sharing your fix. It’s working great. I did get a failing test when I built the latest master though. Here’s the stacktrace I got:
It was only after I skipped the tests that I was able to build the jar and add it to my project’s class path and saw that your fix was working.