Skip to content

Commit

Permalink
Fixed support for checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
fgnass committed Nov 18, 2011
1 parent 44ed25f commit 5051789
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/aspects/relay.js
Expand Up @@ -21,11 +21,11 @@ exports.apply = function($, window, document) {

$.fn.liveUpdate = function() {
this.client('live', 'change', function(ev) {
var val = this.checked === undefined ? this.value : this.checked;
$.sendEvent($.extend({}, ev, {type: 'update', newValue: val}));
var prop = (this.type == 'radio' || this.type == 'checkbox') ? 'checked' : 'value';
$.sendEvent($.extend({}, ev, {type: 'update', which: prop, newValue: this[prop]}));
});
this.live('update', function(ev) {
this[this.checked === undefined ? 'value':'checked'] = ev.newValue;
this[ev.which] = ev.newValue;
$(this).trigger('change');
});
return this;
Expand Down Expand Up @@ -100,6 +100,9 @@ exports.client = function() {
}

$.sendEvent = function(ev) {
if (typeof ev == 'string') {
ev = {type: ev, target: document};
}
if (!ev.sent) {
var msg = flatten(ev);
msg.targetId = ev.target.id;
Expand Down

0 comments on commit 5051789

Please sign in to comment.