Skip to content

Commit

Permalink
Fixes #163 w-for was not being removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip Gates-Idem committed Oct 12, 2016
1 parent c9e94eb commit 76da236
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
6 changes: 2 additions & 4 deletions taglib/TransformHelper/handleWidgetFor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@

module.exports = function handleWidgetFor() {
var el = this.el;
if (!el.hasAttribute('w-for')) {
return;
}

var widgetFor = el.getAttributeValue('w-for');

el.removeAttribute('w-for');

if (widgetFor == null) {
return;
}


// Handle the "w-for" attribute
if (el.hasAttribute('for')) {
this.addError('The "w-for" attribute cannot be used in conjuction with the "for" attribute');
Expand Down
4 changes: 3 additions & 1 deletion taglib/widgets-transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ module.exports = function transform(el, context) {

if (el.hasAttribute('w-id')) {
transformHelper.assignWidgetId();
} else if (el.hasAttribute('w-for')) {
}

if (el.hasAttribute('w-for')) {
transformHelper.handleWidgetFor();
}

Expand Down
3 changes: 2 additions & 1 deletion test/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
"eqeqeq": false,
"latedef": true,
"unused": "vars",
"eqnull": true
"eqnull": true,
"expr": true
}
7 changes: 7 additions & 0 deletions test/autotests-browser/widget-label-for/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = require('marko-widgets').defineComponent({
template: require('./template.marko'),

init: function() {

}
});
4 changes: 4 additions & 0 deletions test/autotests-browser/widget-label-for/template.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div w-bind>
<label w-id="label" w-for="input">foo</label>
<input w-id="input" value="test">
</div>
12 changes: 12 additions & 0 deletions test/autotests-browser/widget-label-for/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var expect = require('chai').expect;

module.exports = function(helpers) {
var widget = helpers.mount(require('./index'), {});
var label = widget.getEl('label');
var forElId = label.getAttribute('for');
var inputEl = document.getElementById(forElId);

expect(forElId).to.exist;
expect(inputEl.value).to.equal('test');
expect(label.getAttribute('w-for')).to.equal(null);
};

0 comments on commit 76da236

Please sign in to comment.