Radio Button Click Event Binding Prevent's Radio Button from being Checked

3,100 views
Skip to first unread message

JWD

unread,
Oct 25, 2011, 12:22:22 AM10/25/11
to knock...@googlegroups.com
I am trying to use the radio button selection to update my model values, but I've had not luck trying several different ways. Any click binding that I add (ie click : function(){ alert('hit');) will fire but will then leave the radio button unchecked. I've also tried subscribing to the observable which I am using for my checked value on the radio button, but that binding seems to be one way as changes to the radio buton selection do not seem to update the observable.

Any direction that anyone can provide would be much appreciated. If I am unable to find a better solution, the only thing I can think to do from here is implement a polling process that checks for update on the selected radio buttons.

JWD

unread,
Oct 25, 2011, 12:24:14 AM10/25/11
to knock...@googlegroups.com
I also tried manually checking the radio button after the click even fire, and no dice using .attr('checked', 'checked'); or .checked = true;

rpn

unread,
Oct 25, 2011, 9:21:25 AM10/25/11
to knock...@googlegroups.com
Hello-
Maybe you can share some of your code or what you want to accomplish.  Typically, you would do something like: http://jsfiddle.net/rniemeyer/sZ4Sh/.  

Hope this helps.


JWD

unread,
Oct 25, 2011, 9:46:14 AM10/25/11
to knock...@googlegroups.com
Thanks rpn,

I owe a lot to what I've learned about Knockout so far to you. I guess I did leave out an important piece of information in that I'm trying to bind the checked value to observableArray, as I have several radio button lists that will be displayed. I forked the jsFiddle at http://jsfiddle.net/CqJ3N/14/ to show you what I'm trying to accomplish. Maybe the issue is that I'm having to bind back to the viewModel? The radio button checked value is read correctly from the array, but does not seem to update back.


JWD

unread,
Oct 25, 2011, 9:55:50 AM10/25/11
to knock...@googlegroups.com
This is a little cleaner, and I even tried making the observableArray contain observables, but still no luck on the 2 way binding.

http://jsfiddle.net/CqJ3N/22/

rpn

unread,
Oct 25, 2011, 10:03:54 AM10/25/11
to knock...@googlegroups.com
You would need a property to attach to like: 

selectedValueArrayko.observableArray([testko.observable('valueA'}])


rpn

unread,
Oct 25, 2011, 10:06:06 AM10/25/11
to knock...@googlegroups.com
Actually, if you do put an observable in your array, then you could do it without an actual property like: http://jsfiddle.net/rniemeyer/CqJ3N/24/

You just would not want to unwrap it in your select binding.  So, remove the last (), as you want to pass the observable and not its value.

JWD

unread,
Oct 25, 2011, 11:12:02 AM10/25/11
to knock...@googlegroups.com
Your the man RPN!

I was able to get what I was looking for, being able to data-bind my radio buttons' checked value to a separate viewModel observableArray and getting the subscription listener to fire like this.

http://jsfiddle.net/CqJ3N/41/

JWD

unread,
Oct 25, 2011, 11:13:07 AM10/25/11
to knock...@googlegroups.com
Thank You!!
Reply all
Reply to author
Forward
0 new messages