dstreet / dependsOn

a jQuery plugin for handling form field dependencies
http://dstreet.github.com/dependsOn
MIT License
106 stars 32 forks source link

Nested Dependencies Issue #5

Closed thomstark closed 10 years ago

thomstark commented 10 years ago

Hi. Thanks for this terrific plugin. I've run into an issue when I have a field dependent upon a dependent field. The structure goes like this:

1) if checkbox1 is checked, show radio1 2) if checkbox1 is checked and radio1 has value of "partial", show textinput1

no.2 works if I disable no.1, but it does not work if no.1 is active.

$("div#container_smartcare_scheduling_ot_type") .dependsOn({"input[type='checkbox'][name='smartcare_scheduling_overtime']":{checked:true}},{valueOnDisable:"",checkOnDisable:false,duration:500});

$("div#container_smartcare_scheduling_ot_hours") .dependsOn({"input[type='radio'][name='smartcare_scheduling_ot_type']":{values:["partial"]},"input[type='checkbox'][name='smartcare_scheduling_overtime']":{checked:true}},valueOnDisable:"",checkOnDisable:false,duration:500});

If I remove the first block, the second block works. If I add the first block, the second block does not work.

Am I doing something incorrectly or is this a little bug?

Thanks for your time!

thomstark commented 10 years ago

I figured out my problem. I was doing both valueOnDisable:"" and checkOnDisable:false because the form is dynamically generated and I was being lazy. valueOnDisable was removing the value from the radio field on page load. Added a check to my code for field type to determine whether to use valueOn or checkOn, and now it's working perfectly.

dstreet commented 10 years ago

Great. I'm glad you were able to find a solution.

thomstark commented 10 years ago

Yeah, me too. :) Thanks again for the great plugin.