Skip to content

Commit

Permalink
Merge pull request #128 from Kanaye/bug-#123
Browse files Browse the repository at this point in the history
Implements checkbox groups and fixes false negative select multple attribute check.
  • Loading branch information
astoilkov committed Jan 8, 2016
2 parents 5156b16 + 547d934 commit b72e8cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/query/DomQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,18 @@ define([
var tagName = element.tagName.toLowerCase();
var type = element.getAttribute('type');

if (type == 'checkbox') {
if (blocks.isArray(value()) && (type == 'checkbox' || type == 'radio')) {
var unwrapedValue = value();
if (element.checked) {
if (unwrapedValue.indexOf(element.value) == -1) {
value.add(element.value);
}
} else if (unwrapedValue.indexOf(element.value) !== -1) {
value.splice(unwrapedValue.indexOf(element.value), 1);
}
} else if (type == 'checkbox') {
value(element.checked);
} else if (tagName == 'select' && element.getAttribute('multiple')) {
} else if (tagName == 'select' && element.getAttribute('multiple') !== null) {
var values = [];
var selectedOptions = element.selectedOptions;
if (selectedOptions) {
Expand Down
8 changes: 6 additions & 2 deletions src/query/VirtualElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,15 @@ define([
if (attributeName == 'checked' && attributeValue != null && !this._fake) {
if (this._attributes.type == 'radio' &&
typeof attributeValue == 'string' &&
value != attributeValue && value != null) {
value != attributeValue && value != null && !blocks.isArray(attributeValue)) {

attributeValue = null;
} else {
attributeValue = attributeValue ? 'checked' : null;
if (blocks.isArray(attributeValue)) {
attributeValue = attributeValue.indexOf(value) !== -1 ? 'checked' : null;
} else {
attributeValue = attributeValue ? 'checked' : null;
}
}
} else if (attributeName == 'disabled') {
attributeValue = attributeValue ? 'disabled' : null;
Expand Down
6 changes: 5 additions & 1 deletion src/query/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ define([

attributeValue = false;
} else {
attributeValue = !!attributeValue;
if (blocks.isArray(attributeValue)) {
attributeValue = attributeValue.indexOf(element.value) !== -1;
} else {
attributeValue = !!attributeValue;
}
}
}

Expand Down

0 comments on commit b72e8cc

Please sign in to comment.