I’m having a logic problem with an implementation of combination rules in Javascript.
In short:
- I define which checkboxes cannot be ‘on’ together with eachother in a JSON object.
- If I click on measure 1 -> measures 7 and 8 get grayed out, this is correct.
- If I click on measure 4 -> measures 8, 9, 10 and 11 get grayed out, this is correct too.
- Now, if I click again on measure 4 -> measure 8 gets active again, but shouldn’t be, because the JSON ‘rules’ state that since measure 1 is still checked, measure 8 must be grayed.
What’s a smart way to solve this logic problem? Thanks in advance!
Basically, how do I remember that clicking ‘measure 1’ already disabled ‘measure 8’, so that toggling ‘measure 4’ won’t accidentally re-enable ‘measure 8’ with ‘measure 1’ still ‘on’?
All code here: https://gist.github.com/1055968
Interactive: http://jsfiddle.net/gnijholt/58zuR/
Well logically i’d do something like this:
an object which stores the rules that
are applied.
remove that rule from the memory
object and before unticking each
checkboxes i’ll go through the memory
object to see if there are any
conflicting rules. If there is one
conflicting rules, i do not gray out
the checkbox.
I’m trying to implement this.
EDIT – i’v implemented my idea. here is a fiddle http://jsfiddle.net/Tvs7E/1/