ocrio.box
(Ivan Ovchinnikov)
October 19, 2017, 7:58am
#1
Hello, community.
We are currently working on views for our app, and we want to add more text fields to edit our datasource by clicking a button. e.g:
Phone Numbers
[PhoneNumber1] [-]
[PhoneNumber2] [-]
[PhoneNumber3] [-]
[+]
So by clicking [-] we wanna delete a row (and delete a string entry from entity)
And by clicking [+] we wanna add a row (and add an entry to an entity)
Is there any way to implement such behavior?
tsarev
(Daniil Tsaryov)
October 20, 2017, 1:28pm
#2
Hello,
Here is the basic implementation. Phones layout:
<vbox expand="spacer"
spacing="true">
<linkButton id="addTextFieldButton"
invoke="addTextField"
caption="[+]"/>
<label id="spacer"/>
</vbox>
addTextField method:
public void addTextField() {
HBoxLayout hBox = componentsFactory.createComponent(HBoxLayout.class);
hBox.setSpacing(true);
TextField textField = componentsFactory.createComponent(TextField.class);
hBox.add(textField);
LinkButton removeTextFieldButton = componentsFactory.createComponent(LinkButton.class);
removeTextFieldButton.setAction(new AbstractAction("removeTextField") {
@Override
public void actionPerform(Component component) {
remove(hBox);
}
});
removeTextFieldButton.setCaption("[-]");
removeTextFieldButton.setAlignment(Alignment.MIDDLE_LEFT);
hBox.add(removeTextFieldButton);
container.add(hBox, container.getOwnComponents().size() - 2);
}
Other logic depends on data model, requirements, etc.
Best regards,
Daniil.
ocrio.box
(Ivan Ovchinnikov)
October 23, 2017, 9:21am
#3
Thanks for that, will try.