Skip to content

Commit

Permalink
Update getAttrs to handle checked and unchecked checkboxes.
Browse files Browse the repository at this point in the history
  • Loading branch information
atogle committed Jul 1, 2014
1 parent 862fc79 commit f68b1c7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*global _, moment, BinaryFile, loadImage, EXIF */
/*global _, moment, BinaryFile, loadImage, EXIF, jQuery */

var Shareabouts = Shareabouts || {};

(function(NS){
(function(NS, $){
'use strict';

NS.Util = {
Expand Down Expand Up @@ -37,13 +37,28 @@ var Shareabouts = Shareabouts || {};
},

getAttrs: function($form) {
var attrs = {};
var attrs = {},
$checkedCheckboxes = $form.find('[type="checkbox"]:checked'),
$uncheckedCheckboxes = $form.find('[type="checkbox"]:not(:checked)');

// Get values from the form
_.each($form.serializeArray(), function(item) {
attrs[item.name] = item.value;
});

// Handle check box values
$checkedCheckboxes.each(function(i, el) {
if (el.name) {
attrs[el.name] = true;
}
});

$uncheckedCheckboxes.each(function(i, el) {
if (el.name) {
attrs[el.name] = false;
}
});

return attrs;
},

Expand Down Expand Up @@ -274,4 +289,4 @@ var Shareabouts = Shareabouts || {};
}
}
};
}(Shareabouts));
}(Shareabouts, jQuery));

0 comments on commit f68b1c7

Please sign in to comment.