Uniform icon indicating copy to clipboard operation
Uniform copied to clipboard

Classes on checkboxes, radio buttons, and selects don't get pulled onto the wrapping divs

Open roubaobaozi opened this issue 11 years ago • 3 comments

div.selector, div.checker, div.radio don't take on the classes of the inputs/selects they wrap, but often adding a class is necessary for certain styling.

I wrote this (all inputs, selects and textareas within .uniform have uniform() run on them):

$('.uniform input:checkbox[class]').each(function() { var checkboxClasses = $(this).attr('class'); $(this).parent().parent('div.checker').addClass(checkboxClasses); }); $('.uniform input:radio[class]').each(function() { var radioClasses = $(this).attr('class'); $(this).parent().parent('div.radio').addClass(radioClasses); }); $('.uniform select[class]').each(function() { var selectClasses = $(this).attr('class'); $(this).parent('div.selector').addClass(selectClasses); });

Which does the job for me. I don't know if there's a better way that could be written. Just thought someone might like it, or know how to .. make this available for all uniform.js users.

Hope this is useful.

Cheers

roubaobaozi avatar Sep 09 '13 08:09 roubaobaozi

I have also come across this problem and have had to implement a hack. But the problem is that sometimes you want classes to be inherited, and sometimes you don't... If they are classes used for styling, it would be important to inherit them. If the classes are used as selectors to implement some functionality, it may not be a good idea... so how do you decide?

One solution I implemented was to take a list of all classes and extract a list of forbidden functional classes using regular expressions, then adding those classes to the wrapper

. I don't see any other way of getting around this...

LeeBurton avatar Nov 26 '13 12:11 LeeBurton

I've started with a rewrite of Uniform to address many concerns. This last comment in particular poses a challenge with my new scheme - I plan on copying all classes to the wrapper. I figure that if you want to style the element, your CSS would use input.some-class instead of .some-class. If you are targeting an element, you could use $('input.some-class') or $('.some-class').not('.uniformjs').

ghost avatar Nov 26 '13 13:11 ghost

Sorry - posted as the wrong user. Look up fidian if you want to contact me about the Uniform rewrite.

fidian avatar Nov 26 '13 14:11 fidian