0

Form binding help

asked 2018-10-20 19:43:32 +0800

psinalberth gravatar image psinalberth
52 6

Hi, how to work with nested objects using form directive? I need to bind an entire object to form object and validate it with all nested objects. Do nested objects have to be FormProxyObject too? I'm also using Hibernate.

<div viewModel="@id('vm') @init('com.person.PersonVM')" validationMessages="@id('vmsgs')">

    <div class="content" form="@id('fx') @load(vm.person) @save(vm.person,before='save') @validator('vm.FormValidator')">

        <label sclass="subtitle is-4" value="Edit Person"/>

        <separator />

        <div class="field">
            <label sclass="label"  value="Name" />
            <div class="control">
                <textbox class="input" value="@bind(fx.name)" />
                <label sclass="help is-danger" value="@load(vmsgs['name'])"/>
            </div>
        </div>

        <div class="field">
            <label sclass="label"  value="Age" />
            <div class="control">
                <intbox class="input" value="@bind(fx.age)"/>
                <label sclass="help is-danger" value="@load(vmsgs['age'])"/>
            </div>
        </div>

        <div class="field">
            <label sclass="label"  value="Street Name" />
            <div class="control">
                <textbox class="input" value="@bind(fx.address.streetName)" />
                <label sclass="help is-danger" value="@load(vmsgs['streetName'])"/>
            </div>
        </div>

        <div class="field">
            <label sclass="label"  value="Number" />
            <div class="control">
                <intbox class="input" value="@bind(fx.address.number)" />
                <label sclass="help is-danger" value="@load(vmsgs['number'])"/>
                <label sclass="help is-danger" value="@load(vmsgs['numberValid'])"/>
            </div>
        </div>

    <button label="Save" onClick="@command('save')"/>

    </div>
</div>
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-10-23 10:07:08 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2018-10-23 10:07:22 +0800

Your code looks correct, the form binding will automatically create a proxy around the nested person.address object if possible so you can validate the streetName before saving it.

Did you encounter any problem there? Did something not work as expected?

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
2 followers

RSS

Stats

Asked: 2018-10-20 19:43:32 +0800

Seen: 6 times

Last updated: Oct 23 '18

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