Thursday, August 1, 2019

id and name attributes with underscores not working well for Bootstrap form elements

I came under a weird situation in laravel/bootstrap form whereby a select drop-down's  "select-element.value" in Javascript would remain the same (the very first one) regardless of which option was actually selected.

Turns out the error went away once I renamed the id and name attributes of the select element to a string without an underscore ('_') in it. I looked it up and although theoretically allowed and mostly non-problematic, underscores have a history of issues in id and other element attribute names under different situations and environments and they are therefore not recommended in guides like this one: https://google.github.io/styleguide/htmlcssguide.html#ID_and_Class_Name_Delimiters

No comments:

Post a Comment