mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-29 00:38:11 -05:00
Modify js to allow checkboxes to send their checked state when desired.
If a checkbox has data-send-checked, send is(":checked") to the form field
instead of the checkbox's value (which is always 'on').
Allows for sending explicit unchecked state.
This commit is contained in:
@@ -85,11 +85,17 @@ function get_form_fields(form, fields, filter_func) {
|
||||
filter_func = function(x) { return true; };
|
||||
/* consolidate the form's inputs for submission */
|
||||
$(form).find("select, input, textarea").not(".gray, :disabled").each(function() {
|
||||
var type = $(this).attr("type");
|
||||
if (filter_func(this) &&
|
||||
( (type != "radio" && type != "checkbox") ||
|
||||
$(this).is(":checked")) )
|
||||
fields[$(this).attr("name")] = $(this).val();
|
||||
var $el = $(this),
|
||||
type = $el.attr("type");
|
||||
if (!filter_func(this)) {
|
||||
return;
|
||||
}
|
||||
if ($el.data('send-checked')) {
|
||||
val = $el.is(':checked');
|
||||
} else if ((type != "radio" && type != "checkbox") || $el.is(":checked")) {
|
||||
val = $el.val();
|
||||
}
|
||||
fields[$el.attr("name")] = val;
|
||||
});
|
||||
if (fields.id == null) {
|
||||
fields.id = $(form).attr("id") ? ("#" + $(form).attr("id")) : "";
|
||||
|
||||
Reference in New Issue
Block a user