diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index 4fe13108d..3c6fc6837 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -2,6 +2,7 @@ import { isUndefined, isArray, isEmpty, + isBoolean, has, clone, isString, @@ -674,7 +675,11 @@ const Component = Backbone.Model.extend(Styleable).extend( const value = isString(val) ? val.replace(/"/g, '"') : val; if (!isUndefined(value)) { - attrs.push(`${attr}="${value}"`); + if (isBoolean(value)) { + value && attrs.push(attr); + } else { + attrs.push(`${attr}="${value}"`); + } } } diff --git a/test/specs/dom_components/model/Component.js b/test/specs/dom_components/model/Component.js index b04f2eede..ae5da0f8e 100644 --- a/test/specs/dom_components/model/Component.js +++ b/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( + '
' + ); + }); + it('Component parse empty div', () => { var el = document.createElement('div'); obj = Component.isComponent(el);