0

How to firing textbox dirty when value is changed from combobox?

asked 2013-03-03 13:41:48 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-03-03 13:43:48 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

Hi everybody,

I have a simple combobox

<combobox id="cmbMMG" autocomplete="true" width="250px" model="@load(vm.lstMMG)" 
            selectedItem="@bind(vm.selMMG)" autodrop="true"
            onSelect="txtMMG.invalidate(); txtMMG.setValue(self.getSelectedItem().getValue().toString())">
                    <template name="model">
                        <comboitem label="@load(each.cognome)" value="@load(each.progressivo)"
                                description="@load(each.nome)"/>
                    </template>
  </combobox>
   MMG:<textbox id="txtMMG" value="@bind(gbD.MMG)" width="30px"/>

My "simple" question is: why onSelect event not firing dirty status in my middle object MVVM while if I edit the field manually the status dirty is correct?

Thanks for the help Luca

delete flag offensive retag edit

5 Answers

Sort by ยป oldest newest most voted
0

answered 2013-03-26 19:32:55 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-03-26 19:32:55 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

SOLVED:

@Command()
public void cmdCambiaCampo(@BindingParam("Combo") Combobox item )
{

    if(item.getId().equalsIgnoreCase("cmbMMG"))
    {
        myForm.setField("MMG", item.getSelectedItem().getValue().toString());
    }
    else if(item.getId().equalsIgnoreCase("cmbInfermieri"))
    {
        myForm.setField("Infermiere_riferimento", item.getSelectedItem().getValue().toString());
    }

    BindUtils.postNotifyChange(null, null, ((FormExt) myForm).getStatus(), "dirty");
}
link publish delete flag offensive edit

Comments

what is myform here ?

Senthilchettyin ( 2013-11-30 07:31:21 +0800 )edit

Form myForm = new SimpleForm(); middle-object

lramellavotta ( 2013-11-30 09:03:52 +0800 )edit

<tabpanel id="tbDettaglio"> <groupbox form="@id('gbD') @init(vm.myForm) @load(vm.selected) @save(vm.selected, before='updUtente()')" id="formGroup" visible="@load(not empty vm.selected)" hflex="true" mold="3d" validationMessages="@id('vmsgs')">

lramellavotta ( 2013-11-30 09:07:33 +0800 )edit
0

answered 2013-03-03 23:35:46 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-03-03 23:37:30 +0800

rdgrimes gravatar image rdgrimes
735 7

In an MVVM pattern, it is the BindComposer that handles the re-rendering, which is what the invalidate flag is for (to notify that the widget needs to be redrawn).

In your example, you have left the BindComposer out of the equation by referencing the textbox Id from the Combobox. Basically, you're doing widget to widget communication. Nothing in what you've done notifies the BindComposer of the fact that something has changed. In MVVM, if something changes on the component side, it will not be reflected to the widget unless you notify the BindComposer. And, vice versa. Make a change on the widget side and it will not reflect on the component side unless you notify BindComposer.

The reason that the dirty flag gets updated when you manually change the textbox value is because you have a @bind in the value attribute that automatically updates the component side of things via BindComposer.

link publish delete flag offensive edit
0

answered 2013-03-04 17:15:24 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-03-04 17:15:24 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

Thanks for the info. I tried to change my program with the following code (and other attempts) but without success.

                <groupbox form="@id('gbD') @init(vm.myForm) @load(vm.selected) @save(vm.selected, before='updUtente()')"
                    id="formGroup" visible="@load(not empty vm.selected)" hflex="true" mold="3d"
                    validationMessages="@id('vmsgs')">
         (other lines code)

MMG/Infermiere 
                        <hbox>
                            <combobox id="cmbMMG" autocomplete="true" width="250px" model="@load(vm.lstMMG)" 
                                selectedItem="@bind(vm.selMMG)" autodrop="true"
                                onSelect="@command('cmdCambiaCampo',txtMMG.setValue(self.getSelectedItem().getValue().toString()))">
                                <template name="model">
                                    <comboitem label="@load(each.cognome)" value="@load(each.progressivo)"
                                            description="@load(each.nome)"/>
                                </template>
                            </combobox>

My Java class:

    @Command
@NotifyChange("selected")
public void cmdCambiaCampo(String txtValore)
{
    selected.setMMG(Integer.valueOf(txtValore));
    BindUtils.postNotifyChange(null,null,Adm_clienti.this,"selected");
}
link publish delete flag offensive edit
0

answered 2013-03-05 02:03:59 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-03-05 02:03:59 +0800

rdgrimes gravatar image rdgrimes
735 7

Is there a reason you are going about this in such a round-about manner? Because you have selectedItem on the Combobox set to @bind to vm.selMMG, it automatically gets saved to the Java component whenever you select a different item. So, if you were to simply @bind your Textbox value to vm.selMMG.someproperty, the Textbox would immediately reflect the value you selected in the Combobox.

link publish delete flag offensive edit
0

answered 2013-03-16 13:03:29 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-03-16 13:03:29 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

Hi, Sorry for the absence but my pc was broken ... @rdgrimes: I'm trying to raise the flag dirty when I select another record from the combobox. I tried in many times but without success...

link publish delete flag offensive edit

Comments

But the reason you're trying to raise the dirty flag is so that the selected value is reflected in textbox, right? If you do as I suggested, you eliminate the need to set the dirty flag. In fact, it is an unnecessary step to achieve your final aim...unless there's a reason you haven't laid out.

rdgrimes ( 2013-03-16 19:22:56 +0800 )edit

My program before doing the update record check which fields have changed creating the query to update only the changed data. If I can not find a way to set dirty a field linked with combobox I'will in real trouble ... Luca

lramellavotta ( 2013-03-18 15:47:30 +0800 )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
2 followers

RSS

Stats

Asked: 2013-03-03 13:41:48 +0800

Seen: 76 times

Last updated: Mar 26 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More