Reputation: 855
What would be the best approach to implement a form with a variable number of text fields? I'm thinking something like this:
textField1 (removeButton)
textField2 (removeButton)
textField3 (removeButton)
addNewTextFieldButton
I would like this to bind to a list of strings.
Upvotes: 0
Views: 577
Reputation: 31225
I achieved this with an editable grid with a single column and buttons to add/delete rows.
This component is very well integrated with GWT Editor framework so you can bind your grid to a list of objects using a ListStoreEditor
Upvotes: 2
Reputation: 705
The best approach would be to use the GWT Editor framework. GXT's fields are very well integrated with the Editor framework.
Here is a very rough example of how you might approach this problem.
You would start by creating one Editor for the thing you are wanting to bind to. In your case, I think a composite which contains a TextField
(which is bound to the string) and a button. The button won't actually bind to anything, but you will provide a way for something which uses this class to register a SelectHandler
against it. Let's call this editor SubEditor
.
Once you create a UI component which is designed to bind to one string, you will next create a ListEditor<String, SubEditor>
which will bind to a List<String>
which will compose a view, consisting of one SubEditor
per each String
in the bound list.
You don't really need to create the SubEditor
, as you could construct something as simple as what you want within your ListEditor's EditorSource
class (read through the tutorials on ListEditors
).
Again, I want to emphasize the this is a ROUGH example on how to get started. I hope there is enough information here for you to fill in the pieces.
The following SO question has helped me out a lot: Using GWT Editors with a complex usecase
Upvotes: 0