tristate
tristate copied to clipboard
Submit value?
Indeterminate should be "visual" only. A checkbox in the indeterminate state should simply mask whether the checkbox is checked or not.
<input id="mycheckbox" name="mycheckbox" value="checked" />
$('#mycheckbox').tristate({
indeterminate: "Maybe"
});
$("#mycheckbox").tristate('state', null);
$("#mycheckbox").prop("checked", true);
We now have a checkbox that displays "indeterminate", but will submit the value "checked" how can I get it to submit the value "Maybe" (as set via the initialization script") ?
a) should $("#mycheckbox").tristate('state', null);
have a 3rd param? true
/false
to specify if the checkbox's masked state is checked/unchecked
b) a new init option: "indeterminateIsChecked": false,
false
seems to be current behavior, I'd like the options for indeterminate to mask "checked"
method to get value for specified state?
we have the ability to set values via html attributes
checkedvalue="Yes" uncheckedvalue="No" indeterminatevalue="Maybe"
or via init function.
how about a function to "get" those values?
// Proposed method:
$("#mycheckbox").tristate('getValue', null); // returns "Maybe"
$("#mycheckbox").tristate('getValue', true); // returns "Yes"
$("#mycheckbox").tristate('getValue', false); // returns "No"
To submit it in a form, you should use the *Value
attributes or corresponding options checked
, unchecked
and indeterminate
. These values are submitted.
Adding a .getValue()
method sound like a nice addition, though they'll have to follow jQuery extension getter signatures (i.e. no value, just a method name like getChecked
, getUnchecked
and getIndeterminate
). If you want to submit a PR for it, please do so, otherwise I'll look into it hopefully next weekend.
... I've solved my submit-value issue via the "change" & "init" callbacks
<input type="checkbox" value="iAmChecked" indeterminatevalue="default" />
$("input[type=checkbox]").tristate({
change: function(state, value) {
if (state === null) {
$(this).prop("checked", true);
$(this).prop("value", value);
} else {
$(this).prop("value", 1);
}
},
init: function(state, value) {
if (state === null) {
$(this).prop("checked", true);
$(this).prop("value", value);
} else {
$(this).prop("value", 1);
}
}
});