-
Notifications
You must be signed in to change notification settings - Fork 36
Linking radio button groups #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've modified my setValue function to this: function setValue(target, field, value) { Not sure if it's broken anything yet... I guess it assumes a form parent. Presumably this will also be a problem for groups of checkboxes. And how does it handle a multi select element? |
The current implementation only supports:
I have a fork demonstrating declarative linking that does support checkboxes, checkbox lists and radio buttons, but I am now working on modifications to datalink itself to support these controls directly. Your fix is similar to the approach I am taking, but in many cases it is necessary to update the linking code from element to object AND from object to element. Also, I am trying to support both single checkboxes linked to boolean fields and sets of checkboxes linked to arrays of values (two very reasonable common scenarios). The biggest issue with the link() API right now is it relies exclusively on the val() method. For the line, $(target)setter;, the setter will always be "val" in the current codebase despite indications otherwise. As many have noted on the jQuery forums, val() does not handle checkboxes and radio buttons in an elegant/intuitive way, so it is necessary to implement workarounds as you have suggested. |
It might be helpful to others to call out this limitation (limited / no checkbox & radio input handling) in the readme or on the jQuery Plugin API docs. |
I've got a code hack that works around this. For the following radio button set:
I've added this function in my main include:
Essentially (as near as I can tell), this sets the values to their original before the datalink overwrites the values with the values from the object. When you click type0, type0 becomes 1, type1 becomes 2, then type0, type1, and obj.type all become 1. When you click type1, type0 becomes 1, type1 becomes 2, then type0, type1, and obj.type all become 2. I know it's not an ideal workaround, but since this has been open for 6 months now, hopefully this will help people who come here wonder what's wrong with their radio buttons. |
I had a problem with setField() due to exactly this. So I took the fix from @critchleyjs and adapted it slightly. You can see the result here: http://stackoverflow.com/questions/6071806/setting-radio-buttons-with-setfield-in-datalink-jquery Thanks critchleyjs! |
OK, and now I added the hack (for radio buttons and checkboxes to a fork). |
Mind you, this hack seems to have broken things. When you now click a checkbox, it stays checked, and you cannot uncheck it :-( |
Updated the SO overflow question with my changes that fix this issue. http://stackoverflow.com/questions/6071806/setting-radio-buttons-with-setfield-in-datalink-jquery |
When linking a field with a radio group, after selecting an item the value of all radios in that same radio group change to the same value as the radio that was clicked.
So if I had:
Yes Noafter clicking on Yes (true) the value of RegisteredBusiness_1 is changed to "true". This makes it hard/impossible to work linking with radios.
The text was updated successfully, but these errors were encountered: