Hello-
I have an ObservableObject bound to a remote datasource, and the ObservableObject is bound to form fields with MVVM.
I currently have a 1-1 relationship between the field and the form input. However, I want to change that so there is a single field for multiple controls. For example...
Current
isClient database field (boolean) --> isClient checkbox
isPrimeClient database field (boolean) --> isPrimeClient checkbox
Desired
clientType database field (integer) --> isClient checkbox, isPrimeClient checkbox
I think I can use binding to the observable's "get" and "set" events...
observable.bind("set", function (e) {
if ((e.field === "isClient") || (e.field === "isPrimeClient")) {
let isClient = observalbe.get("isClient");
let isPrimeClient = observalbe.get("isPrimeClient");
//// Some logic to determine appropriate value for clientType /////
observable.set("clientType",somevalue);
}
});
observable.bind("get", function (e) {
if (e.field === "isClient") {
//Look at clientType integer value and set e.value (for isClient) appropriately.
let clientType = observable.get("clientType");
e.value = //// some logic to determine appropriate value ////
}
else if(e.field === "isPrimeClient"){
//Look at clientType integer value and set e.value (for isPrimeClient) appropriately.
let clientType = observable.get("clientType");
e.value = //// some logic to determine appropriate value ////
}
});
However, observable.get(...) always returns null. Why is that?
Basically what I'm trying to do is take a single field from the back-end and render two controls for it.