Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report Fix uncorrect '0' receive by binders if html attribute is not … #569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions spec/rivets/binders.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,25 @@ describe("Rivets.binders", function() {
Should(fragment.childNodes.length).be.exactly(1);
});
});

describe("Custom binder with no attribute value", function() {
rivets.binders["custom-binder"] = function(el, value) {
el.innerHTML = "received " + value;
};
beforeEach(function() {
el = document.createElement("div");
});

it("receives undefined when html attribute is not specified", function() {
el.innerHTML = "<div rv-custom-binder></div>";
var view = rivets.bind(el);
Should(el.children[0].innerHTML).be.exactly('received undefined');
});

it("receives undefined when html attribute is not specified", function() {
el.innerHTML = "<div rv-custom-binder=''></div>";
var view = rivets.bind(el);
Should(el.children[0].innerHTML).be.exactly('received undefined');
});
});
});
3 changes: 3 additions & 0 deletions src/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export function parseType(string) {
value = null
} else if (string === 'undefined') {
value = undefined
} else if (string === '') {
// string==='' means the Html attribute is empty, binder should receive undefined
value = undefined
} else if (isNaN(Number(string)) === false) {
value = Number(string)
} else {
Expand Down