Hi!
I am using sideview utils 2.4.8 with splunk 4.3 and I am trying to reset the value of a checkbox (basically uncheck it).
Currently I have a little custom behavior that overrides the onContextChange function of the module, and hides the checkbox when the context change. But everything I have tried to do to uncheck this module doesn't seem to work (namely this.container.checked=false, this.input.check=false ...)
Can someone gives me a hint on how to do it?
Here is the code of the custom behavior:
Sideview.utils.declareCustomBehavior("hideComparativeModule", function(htmlModule) {
var visibilityReason = "customBehavior hides the module initially";
htmlModule.hide(visibilityReason);
// preserve the existing onContextChange method.
var methodReference = htmlModule.onContextChange.bind(htmlModule);
// now override the onContextChange method
htmlModule.onContextChange = function() {
var context = this.getContext();
if (context.get("single") == -1) {
this.show(visibilityReason);
} else {
// Need some code here to reset the module to unchecked when hiding!!!
this.hide(visibilityReason);
}
// but note that we both call the original method, and we also are
// careful to return the original method's return value.
return methodReference();
}
});
Many thanks
this.input.removeAttr('checked');
// and as a best practice, call this too:
this.onPassiveChange();
Completely Different Idea:
You can actually do this with no custom code.
1) If you set the customClass param on the Checkbox to something like "hideBecauseSingleIs$single$",
and then define a CSS class hideBecauseSingleIsTrue { display:none;}
that will take care of the visibility change.
2) If you put a ValueSetter just upstream from the Checkbox, set "name" to the same name as the Checkbox module, set "value" to the "offValue", or null, space, etc.. And then use the requiredKeys param to "single", then it will prepopulate (in this case uncheck) the Checkbox, but only in the cases where single is defined.
Granted, if you're comfortable with customBehavior, maybe that's an easier path. Just pointing out that another option exists.
Other Notes:
is the value of $single$ actually "-1"? If it's null or emptystring (far more likely, then that comparison you have there will fail)
Also just to avoid confusing yourself you probably want to rename that htmlModule variable to "checkboxModule". I think it was copied and pasted from a customBehavior defined on an HTML module.
this.input.removeAttr('checked');
// and as a best practice, call this too:
this.onPassiveChange();
Completely Different Idea:
You can actually do this with no custom code.
1) If you set the customClass param on the Checkbox to something like "hideBecauseSingleIs$single$",
and then define a CSS class hideBecauseSingleIsTrue { display:none;}
that will take care of the visibility change.
2) If you put a ValueSetter just upstream from the Checkbox, set "name" to the same name as the Checkbox module, set "value" to the "offValue", or null, space, etc.. And then use the requiredKeys param to "single", then it will prepopulate (in this case uncheck) the Checkbox, but only in the cases where single is defined.
Granted, if you're comfortable with customBehavior, maybe that's an easier path. Just pointing out that another option exists.
Other Notes:
is the value of $single$ actually "-1"? If it's null or emptystring (far more likely, then that comparison you have there will fail)
Also just to avoid confusing yourself you probably want to rename that htmlModule variable to "checkboxModule". I think it was copied and pasted from a customBehavior defined on an HTML module.
You are totally right with the htmlModule. But my code is really ugly right now (I duplicate customBehavior to hide module for each module, because they don't hide on the same condition...). I would love to have only one nice function that takes some parameters as input (namely the $single$ value) and hides if it's equal to something, but I can't find how to pass parameters in the onContextChange overwrite function.
Many thanks for the detailed answer. I just tried it and it works perfectly. I think I will stay with the customBehavior as I have quite some now.
Actually the value of $single$ is -1, so it does work (I tend to overkill and always set an onValue AND an offValue)