Skip to content
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

Submit value? #7

Open
bkdotcom opened this issue Dec 5, 2016 · 2 comments
Open

Submit value? #7

bkdotcom opened this issue Dec 5, 2016 · 2 comments

Comments

@bkdotcom
Copy link

bkdotcom commented Dec 5, 2016

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"
@vanderlee
Copy link
Owner

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.

@bkdotcom
Copy link
Author

bkdotcom commented Dec 5, 2016

... 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);
		}
	}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants