0

I have an address form for multiple addresses.

http://jsfiddle.net/VAs5r/6/

When the form is loaded, the addresses object has a value Active:false that is bind to the enable property to all the input fields in order to block any entry. Then a button named "new address" change the Active property to true in order to enable all the inputs and let the user to enter information.

Is working but the problem is that is not refreshing the fields until you change the select option and then return again to the current address type.

Is there any work around to this?

Thanks.

VAAA
  • 14,531
  • 28
  • 130
  • 253

1 Answers1

0

Here is your fiddle, updated and working.

The problem you were having is that this is not a valid way to set observable values:

self.selectedAddress().active=true;

In knockout, observables are functions, and are set by passing new values to them as parameters, like this:

self.selectedAddress().active(true);

When you set observables the way you were doing it, their "observability" is overwritten, and they become standard objects. When this happens, the UI is not notified of their updates.

Kyeotic
  • 19,697
  • 10
  • 71
  • 128
  • I have added visible: selectedAddress().active to the remove button and it only appears when the selected address is active.. adding visible: !selectedAddress().active to the new address button dont work. any clue? – VAAA Jul 06 '12 at 17:00
  • 1
    Just found the solution: visible: !selectedAddress().active()... very tricky knockout :) Thanks – VAAA Jul 06 '12 at 17:03
  • @VAAA, yeah if you are just binding on the property you dont need the parens, but if you have anything else in there you do. – Kyeotic Jul 06 '12 at 17:10
  • Tyrsius, is not possible to have the address TypeName (home, office, etc) in the select element? This is because when I get the json from server I dont get all the address types, just the address types that the record has associated. Thanks – VAAA Jul 12 '12 at 17:30
  • By the way just publish a new question related to this also but I think more complex :) Thanks for your help. http://stackoverflow.com/questions/11457298/how-two-merge-2-json-objects-into-one – VAAA Jul 12 '12 at 17:31