0

MVVM Complex form for which I want databinding active and do the validation only on button click

asked 2015-06-19 15:48:52 +0800

WilliamB gravatar image WilliamB
1609 1 6

updated 2015-06-19 17:35:08 +0800

I've a big form and a lot of dynamic settings in it.

For exemple when the user pick something in a combobox, I've to go fetch data in the database to fill a listbox. When the user type something in a text field, I've to add the item in a combobox etc ...

So I'm calling my VM quite a bit, from either Setters or Command. I want the validation to be only active when the user click the SAVE button at the end of the form.

And then I wanna display validation error on each fields, either format error or database constraint related error.

I've read http://books.zkoss.org/zk-mvvm-book/7.0/data_binding/validator.html but it turns out that in both Property Binding & Save Before Command approach, there is "Not save data to ViewModel".

I want my form to save to view model even if it's not ok, because i would like to do the validation only when the user Click, but still have access to the bean and not use a mid-layer build.

Maybe a way to do it, would be to bind it at the same time to my VM bean and to a mid-layer form bean?

Hoping I didn't make too much of a mess of this message and that someone can help me.

Regards,

EDIT: Kinda cheated and did :

   <grid form="@id('offreValidation') @load(vm.offer) @save(vm.offer, before='validate') 
        @validator('com.orange.octave.web.viewmodels.contrat.detail.offreentite.validator.OffreCreationValidator', offreValidation=vm.offer)">
delete flag offensive retag edit

Comments

1

willeam, maybe you can use this approach better : throw a WrongValueException in the setter. (like this you can still save to the vm)

chillworld ( 2015-06-21 08:31:08 +0800 )edit

Hey Chill, thanks for your reply. I'll check it out.

WilliamB ( 2015-06-22 09:04:09 +0800 )edit

Well thje issue is, I don't have access to the component in the setter. I could always wire them in the VM but it's kinda dirty isn't it?

WilliamB ( 2015-06-22 20:43:35 +0800 )edit

@SelectorParam can retrieve components based on css3 selector. Thats mvvm style.

chillworld ( 2015-06-22 21:51:30 +0800 )edit

Thanks Chill didn't know about that one.

WilliamB ( 2015-06-23 15:31:10 +0800 )edit
Be the first one to answer this question!
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: 2015-06-19 15:48:52 +0800

Seen: 18 times

Last updated: Jun 19 '15

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