mdesign/md.character_count.ee_addon — pull request #5 by thechrisroberts (2014-01-31 00:05:27+00:00)
Title: Fix for false matches inside grids

Grid fields have id's separate from channel fields, so a grid field may have the same id # as a channel field. When the field is output, both grid fields and channel fields have the id set as id="#field_id_1" so it is possible for a grid field id to be the same as a channel field id meaning md character count could have a false match with a field inside a grid. In my case, md character count matched a select element inside a grid, which doesn't even make sense, but the select had the same id as an input field that had a limit set.

Form fields have both the id and the name set. For channel fields, the id and the name are the same. For grid fields, the id uses the id of the field, but the name uses the id of the grid.

The fix is to take any elements that match the id selector and further filter them, matching them against the name. If both the name and id match, we have a channel field and the counter is added. If they do not match, we have a grid field and nothing happens.

A filter is used since the name selector is a lot slower than an id selector. It's faster to match id's then filter down just the few id matches rather than trying to match globally on the name.