Friday, March 29, 2013

Disable DotNetNuke 7 styling for checkboxes and radio lists

DNN7 replaces input checkbox and radio list controls with custom styling.  For checkboxes, the original checkbox input is hidden and replaced in the UI with an image.  Furthermore the DNN functionality breaks when the input checkbox is rendered by a repeater (e.g., within a table row), making the checkbox unusable.

The method that causes the DNN functionality for checkboxes and radio list controls is declared in dnn.jquery.js and is called $.fn.dnnCheckbox
Here are four possible solutions:

  • Delete the content of the $.fn.dnnCheckbox function declared in dnn.jquery.js (located in \Resources\Shared\scripts).  The problem with this approach is a DNN site upgrade will restore the DNN functionality.
  • Put this script block in the page header after dnn.jquery.js is loaded:
  1. <script type="text/javascript">
  2.     (function () {
  3.         $(document).ready(function () {
  4.             $.fn.dnnCheckbox = function (options) { };
  5.         });
  6.     }());
  7. </script>
  • Run this script after the checkbox control has rendered:
  1. function RemoveDnnCheckboxFormat() {
  2.     $('.dnnCheckbox').remove();
  3.     $(':checkbox').removeAttr('style');
  4. }
  • (updated - thanks to comments from Anonymous) Add the class “normalCheckBox” or “normalRadioButton” to CheckBox or RadioButtonList controls, respectively.

11 comments:

  1. can you type the on prerender function

    ReplyDelete
  2. Sorry Shady I don't know what you need. Please explain in more detail and I'll try to help.

    ReplyDelete
  3. it's pretty ignorant for DNN to implement this in such a way that it high jacks all check boxes, even ones within custom modules.

    ReplyDelete
  4. OMG.. after looking at the code within the $.fn.dnnCheckbox module you can see that the DNN guys were not so ignorant after all. just add the following class to your checkbox and DNN will ignore it.. .normalCheckBox


    Your solution is a bit over kill!

    ReplyDelete
    Replies
    1. Thanks for pointing out the normalCheckBox class - I missed that when inspecting the DNN method. I don't think my solution is overkill - it is a quick way to disable that unwanted DNN functionality without having to go back through and restyle all existing Checkbox/Radiobutton controls. However it certainly is nice to know about your CSS class solution as another way to fix this problem.

      Delete
  5. You're my hero...been beating my head against the wall for a few days now trying to figure out why my module is not working and it is because of the dnn.jquery.js formatting they are doing with checkboxes and radio lists, really messed things up and this hack fixed it!

    ReplyDelete
  6. I just ran afoul of this problem but also found the .normalCheckBox solution. DNN developers weren't ignorant but they sure were azz backwards with this. Now developers have to go back and retrofit their screens with this solution in order NOT for their controls to NOT be customized. It should've been the other way around: Any controls wanting the customization should've required the CSS class.

    ReplyDelete
  7. Is there a similar fix for the fileupload? the wrapper adds in a 'choose file' button that is having issues and I'd like to just stick with the unwrapped telerik async file upload. I've tried editing the dnn.jquery.js file, restarting dnn, but it doesn't recognize my changes. Thanks!

    ReplyDelete
    Replies
    1. Yes you can disable or alter the existing DNN method similar to what I've shown for the checkbox/radio button issue. See this new post for details:
      http://codemeek.blogspot.com/2013/08/customize-dotnetnuke-7-display-for-file.html

      Delete
  8. Actually you shouldn't have to add a class in order to get the normal default behavior/appearance. If anything, you should have to add a class in order to have DNN style it this way. They got it backwards.

    ReplyDelete