-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I am using MVVM and have use case where custom constraint should be loaded later. It seems combobox does not check 'strict' constraint on server side, but on client side only, so when I use with @load, strict constraint check is skipped..
Here is an example
I did one workaround and it works now. Can someone confirm is this good approach?
Is there any special reason you have to set a constraint with data binding instead of EL? Since, you usually need to set it once without changing it at run-time. If so , EL works.
When you use data binding, if you don't specify a ViewModel, you have to apply BindComposer
, or data binding doesn't work. I don't see it in your zkfiddle. So @load()
doesn't work.
<window border="normal" title="Combobox Constraint" apply="org.zkoss.bind.BindComposer"/>
Combobox has an issue that users might enter a non-existed value, you can set it readOnly="true"
to avoid this issue. Or use <searchbox>
alternatively.
Hi, sorry for late answer, I was sick.
I have to use data binding and @load instead of EL. I am re-using templates (UI Template Injection with applying template name and not path of zul). In those templates I cannot use EL, because constraint is calculated later.
So, have I to use apply="org.zkoss.bind.BindComposer"
never-mind do I use MVC or not?
Regarding searchbox
That component does not have constraint at all?? How that helps me?
I update your case https://zkfiddle.org/sample/3l1o9r9/5-Combobox-Load-Constrain
(add BindComposer), the constraint, @load(cct)
, is set as expected. Since in your original fiddle case, you don't use a ViewModel, you have to apply BindComposer to make data binding work.
In your real application, if the page is injected by <apply>
, and you already apply its parent page with BindComposer then the data binding will work. By default, if you use a viewmodel with viewModel="@id(vm)@init(...)"
, zk will apply a BindComposer implicitly.
As I understand, the reason you put the custom constraint is to make user input can only be one of the combobox items. That's the common problem of combobox: it allows user to enter a value that doesn't exist in comboitem. You can make combobox read-only to avoid users from entering arbitrary values. Or using Searchbox.
Searchbox only allows an end-user to enter a value in its value list, so it doesn't need a custom constraint to validate user input.
Asked: 2021-09-08 16:09:16 +0800
Seen: 18 times
Last updated: Sep 17 '21