Skip to content

Commit

Permalink
Safari checkbox selection bug fix
Browse files Browse the repository at this point in the history
For inputs of type checkbox, selections do not apply and should return
null. Safari throws a type error. This code checks for that condition
to ensure an error is not thrown.
  • Loading branch information
dmjio committed Aug 25, 2018
1 parent 580d678 commit 48109ec
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions jsbits/delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ window.objectToJSON = function objectToJSON (at, obj) {

/* If obj is a non-list-like object */
var newObj = {};
for (var i in obj)
for (var i in obj){
/* bug in safari, throws TypeError if the following fields are referenced on a checkbox */
/* https://stackoverflow.com/a/25569117/453261 */
/* https://html.spec.whatwg.org/multipage/input.html#do-not-apply */
if (obj['type'] == "checkbox" && (i === "selectionDirection" || i === "selectionStart" || i === "selectionEnd"))
continue;
if (typeof obj[i] == "string" || typeof obj[i] == "number" || typeof obj[i] == "boolean")
newObj[i] = obj[i];
return (newObj);
}
return newObj;
};

0 comments on commit 48109ec

Please sign in to comment.