Browse Source

Manage correctly boolean attributes in HTML output. Fixes #943

pull/947/head
Artur Arseniev 9 years ago
parent
commit
9a71368f43
  1. 7
      src/dom_components/model/Component.js
  2. 13
      test/specs/dom_components/model/Component.js

7
src/dom_components/model/Component.js

@ -2,6 +2,7 @@ import {
isUndefined, isUndefined,
isArray, isArray,
isEmpty, isEmpty,
isBoolean,
has, has,
clone, clone,
isString, isString,
@ -674,7 +675,11 @@ const Component = Backbone.Model.extend(Styleable).extend(
const value = isString(val) ? val.replace(/"/g, '"') : val; const value = isString(val) ? val.replace(/"/g, '"') : val;
if (!isUndefined(value)) { if (!isUndefined(value)) {
attrs.push(`${attr}="${value}"`); if (isBoolean(value)) {
value && attrs.push(attr);
} else {
attrs.push(`${attr}="${value}"`);
}
} }
} }

13
test/specs/dom_components/model/Component.js

@ -145,6 +145,19 @@ module.exports = {
); );
}); });
it('Manage correctly boolean attributes', () => {
obj = new Component();
obj.set('attributes', {
'data-test': 'value',
checked: false,
required: true,
avoid: true
});
expect(obj.toHTML()).toEqual(
'<div data-test="value" required avoid></div>'
);
});
it('Component parse empty div', () => { it('Component parse empty div', () => {
var el = document.createElement('div'); var el = document.createElement('div');
obj = Component.isComponent(el); obj = Component.isComponent(el);

Loading…
Cancel
Save