What would be the best way to model having duplicate fields hidden by a checkbox?
e.g.
Text: Shipping Address Part 1:
Text: Shipping Address Part 2:
Text: Billing Address Part 1:
Text: Billing Address Part 2:
CheckBox: Billing Address Differs from Shipping Address.
The address editing panel is set up as a separate VM, as is the customer that it binds to.
e.g.
AddressPanel
cust = observable(new customer())
shippingAddress1 = computed( delegates to customer shipping)
shippingAddress2 = observable( delegates to customer shipping )
billingAddress1 = computed(!alternateAddress ? cust.shippingAddress : cust.billingAddress)
billingAddress2 = computed(!alternateAddress ? cust.shippingAddress2 : cust.billingAddress2)
alternateAddress = observable(false)
But the problem is, updating the alternate/address when the customer changes externally / page load, editing the fields (when to sync or not)
The end result should be that if alternate is not ticked, then billing has the same value as shipping.
Do I want to push the writes out from the observable and update others, or pull them from the read somehow?
I think alternate Address itself should be a computed, but then how do I tell the difference between human input telling the address to show, (and breaking the sync, (or should it even break?)) vs the selected customer changing?
(I'm imagining that changing the selected customer should reset the state to how the page loads.)
In reality I have about 4-6 fields that all correspond off this checkbox, and I'm constantly chasing bugs to do with the alternate data either getting stuck, not replicating, or starting in an invalid state.
Cheers,
Ryan Leach