<input type="text"
value.bind="parent.globalInformation"
disabled.bind="parent.childs.filter((e, i) => { return (e.someField) }) > 0">
I suppose you already have something like above, in working form:
<input type="text"
value.bind="parent.globalInformation"
disabled.bind="hasOneValidItem(parent)">
export class MyVm {
hasOneValidItem(parent: Parent) {
return parent.children.some(child => child.someField > 0);
}
}
Now the issue comes when in some of the children, someField
fields were changed from lesser than or equal to 0
to greater than 0.
By default, Aurelia does not do deep observation, like this scenario. So in order to update the binding, there needs to be some hint:
- Binding Signaler (global signaling)
- Value Converter (local signaling)
Or you can use dirty checking, which is pretty cheap if the number of children is not big.
With binding signaler, simply change the template to:
<input type="text"
value.bind="parent.globalInformation"
disabled.bind="hasOneValidItem(parent) & signal :some-field-changed">
Then you can inject BindingSignaler
imported from 'aurelia-templating-resources'
and signal somne-field-changed
.
With value converter, simply change template to:
<input type="text"
value.bind="parent.globalInformation"
disabled.bind="hasOneValidItem(parent) | signalFieldChange: signalCount">
The value converter is just an identity function, basically to return whatever the value is given to it. Its main purpose is to help binding reevaluate the expression whenever view model signalCount
got changed. Then whenever you modify the Child.someField
, increase view model signalCount
by one and you get your UI updated.