Skip to content

Commit

Permalink
Fix box component: radio/checkbox-groups weren't being added
Browse files Browse the repository at this point in the history
  • Loading branch information
vpetrov committed Jan 5, 2014
1 parent 794c495 commit 4b3d65e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
13 changes: 11 additions & 2 deletions adapters/jquery.mobile.1.3.0.js
Expand Up @@ -1058,6 +1058,7 @@ Adapter.prototype.group = function (obj) {
items = autil.extract(obj, 's-items'),
label = autil.extract(obj, 's-label'),
direction = autil.extract(obj, 's-direction', 'vertical'),
box = autil.extract(obj, 's-box'),
fieldset,
container,
container_opt,
Expand Down Expand Up @@ -1088,9 +1089,14 @@ Adapter.prototype.group = function (obj) {
label_opt = {
'tag': 'label',
'html': label,
'for': id, //this ID shouldn't exist for group items, but it helps locate this label
'class': 'fieldset-label'
};

if (box) {
label_opt['data-box'] = box;
}

if (opt['s-embedded']) {
opt['data-corners'] = false;
}
Expand Down Expand Up @@ -1135,6 +1141,7 @@ Adapter.prototype.group = function (obj) {
}
//make sure the object is not wrapped in a container
obj['s-container'] = false;
obj['s-box'] = box;
this._append(fieldset, obj);
return;
}
Expand All @@ -1144,6 +1151,7 @@ Adapter.prototype.group = function (obj) {
if (obj.hasOwnProperty(i)) {
if (typeof (obj[i]) === 'object') {
obj[i]['s-embedded'] = true;
obj[i]['s-box'] = box;
this._append(fieldset, obj[i]);
} else {
cid = id + (++idc);
Expand All @@ -1152,12 +1160,13 @@ Adapter.prototype.group = function (obj) {
'name': id,
's-type': gtype,
'value': obj[i],
's-container': false
's-container': false,
'data-box': box
};

ilabel = this.label({
"html": i,
"for": cid
"for": cid,
});

this._append(fieldset, [ilabel, item]);
Expand Down
30 changes: 29 additions & 1 deletion public/js/box.js
Expand Up @@ -57,9 +57,35 @@ define(


items.each(function () {

var hidden = $('<input type="hidden">').get(0),
label = labels.filter('[for=' + this.id + ']').first().html(),
label,
escapedValue;


if ((this.type === 'radio' || this.type === 'checkbox')) {
//Skip radios or checkboxes that haven't been selected
if (!this.checked) {
return;
}

label = labels.filter('[for=' + this.name + ']').first().html();

//find the label for this radio/checkbox
var ilabel = box.parent().find('label[for=' + this.id + ']').first().text();

//use the input label as the user-visible value
//e.g. for a Yes/No radiogroup, the escaped value will be 'Yes' or 'No',
//instead of '0' or '1'
if (ilabel) {
escapedValue = ilabel;
} else {
escapedValue = 'N/A';
}
} else {
label = labels.filter('[for=' + this.id + ']').first().html();
escapedValue = dummy.text(this.value).html();
}

hidden.value = this.value;
hidden.name = this.name;
Expand All @@ -68,6 +94,8 @@ define(
'</strong></span> ';

newitems.push(hidden);

$(this).removeClass('valid');
});

//clear all items, except hidden elements, and do not trigger 'change' events for cleared elements
Expand Down

0 comments on commit 4b3d65e

Please sign in to comment.