From 71f274762e90d0d521ebb671982ac37b46e8dcf6 Mon Sep 17 00:00:00 2001 From: Jason Harvey Date: Tue, 26 Feb 2013 22:23:19 -0800 Subject: [PATCH] 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. --- r2/r2/public/static/js/reddit.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/r2/r2/public/static/js/reddit.js b/r2/r2/public/static/js/reddit.js index 4b3efda83..574e6aec7 100644 --- a/r2/r2/public/static/js/reddit.js +++ b/r2/r2/public/static/js/reddit.js @@ -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")) : "";