Allow attr() helper method to receive false as value
jfelip937 opened this issue · comments
PROBLEM
With attributes that only their presense is checked (like disable
) we can not remove them with the method attr()
.
PROPOSED SOLUTION
To be able to send false
as value if we want to remove the attribute (in case that we want to set "false" as a attribute value we can send it as string):
attr(elem, "disabled", false)
Right now false
has the same behaviour as null
and it returns the attribute value.
ALTERNATIVE SOLUTION
New method to remove attributes. Still the other solution seems better to me as we can do things like attr(elem, "disabled", checkbox.checked)
.
The same applies to the data(query, attribute, 0)
method. I think changing this line to if(value == null)
would work correctly.
We'll introduce a couple of new methods for now (see #54) to be able to remove attributes and data-*, but for the sake of reference, we also discussed the following ideas:
attr(elem, "disabled", { remove: true })
=> new explicit API to force removeattr(elem, "disabled", false)
=> automatically detect boolean attributes (https://meiert.com/en/blog/boolean-attributes-of-html/) and remove them if they received false or "false"
#54 has been merged 🎉
@jfelip937 @franpb14 feel free to close this one or keep it open to analyze/discuss new APIs and possibilities