In-Field-Labels-jQuery-Plugin icon indicating copy to clipboard operation
In-Field-Labels-jQuery-Plugin copied to clipboard

Can't find fields with special characters in id

Open sanchopancho13 opened this issue 15 years ago • 4 comments

If a field has an id with special jquery selector characters, then inFieldLabels can't find the field from the label's for tag. These ids should be escaped when constructing the jquery selector.

The special jquery characters listed in the jquery API are:

!"#$%&'()*+,./:;<=>?@[]^`{|}~

sanchopancho13 avatar May 12 '11 13:05 sanchopancho13

Adding this line of code immediately before constructing the $field variable seems to work:

for_attr = for_attr.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, "\\$1");

sanchopancho13 avatar May 12 '11 13:05 sanchopancho13

A simpler alternative would be to fetch the element using $(document.getElementById(id)) (which doesn't need escaping), and then checking if it matches the requisites (either textarea or text-ish input). On a side note, it would be faster than even the current implementation, leave alone adding a regex replacement.

instanceofme avatar Feb 07 '12 16:02 instanceofme

This solution works well - perhaps a similar solution (perhaps with better performance, if that exists) should be pushed to the master.. Cheers @sanchopancho13

andrewkhan1 avatar Sep 21 '12 11:09 andrewkhan1

@sanchopancho13 Thanks for your suggested fix, but I agree with @streetpc. I'll just switch to getElementById.

dcneiner avatar Mar 08 '13 03:03 dcneiner