0

Use a combobox to create a new item

asked 2017-10-06 21:08:52 +0800

ajamardo gravatar image ajamardo
21 2

Is there a way to create a new element through a combobox?

What I mean, is in the case that the autocomplete is activated, if the written string doesn't apply to any of the list and the user presses 'enter', get the string and use it to create a new item, or well, manipulate it in the view model?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-10-12 16:59:51 +0800

ajamardo gravatar image ajamardo
21 2

I found a hack for this, even I think there should be a better solution. Anyway, I'll write it here, so I may get some feedback.

Given the combobox:

<combobox hflex="1" selectedItem="@save(vmApp.selectedModel)" model="@load(vmApp.model)" onChange="@command('createActivitySite', event=event)" autodrop="true" autocomplete="true" >
    <template name="model" var="comboItem">
        <comboitem hflex="1" label="@load(comboItem.getColumn('name').value)" />
    </template>
</combobox>

And the events are based on the onChange event. In case there is an onChange and not selected item, I create a new one, as:

public void createActivitySite(@BindingParam("event") InputEvent e){
    if (getSelectedModel()==null){
        // if selected model is null, means that we have to create a new record
        // Creation of the new record code
    } else {
        // that means that the on change is based on a selection of an existing item
        // set the item with the selected model
    }
    BindUtils.postGlobalCommand(null, null, "addSite", args);
}
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2017-10-06 21:08:52 +0800

Seen: 10 times

Last updated: Oct 12