deselect radio's in a group

Dear all,
Thomas Kissner showed me a way to add undo-buttons to radio-buttons in a Group. Together we wrote the following, which is explained on http://www.trialdatasolutions.com/tds/howto/deselectradio.jsp You can also download a sample CRF there.
Kind regards,
Gerben Rienk

Comments

  • GerbenRienkGerbenRienk Posts: 750 ✭✭✭
    <div id="UndoRadio_Col"></div>
    <script type="text/JavaScript" language="JavaScript" src="includes/jmesa/jquery.min.js"></script>
    <script>
    $.noConflict();
    jQuery(document).ready(function($){
      function Display_Undo_Buttons_In_Column(ColNo){
        $('#UndoRadio_Col').parent().parent().parent().parent().find('tbody > tr:visible').each(function(i){
          // only add the undo image, if it doesn't exist
          if ($(this).children('td:nth-child('+ColNo+')').find('.undoradio').length == 0){
           
            if ($(this).children('td:nth-child('+ColNo+')').children('br').length != 0){
              $(this).children('td:nth-child('+ColNo+')').children('br').last().after("<img class='undoradio' title='Click to deselect entry' alt='Click to deselect entry' src='images/bt_Restore.gif'>"); 
            }
            else{
                     $(this).children('td:nth-child('+ColNo+')').children('input[type=radio]').last().after("<img class='undoradio' title='Click to deselect entry' alt='Click to deselect entry' src='images/bt_Restore.gif'>"); 
            }
          }
        });
      };
      function UndoRadio(){
        $("img.undoradio").each(function (){
          $(this).click(function (e){
            var groupName = $(this).parent().find('input[type=radio]').attr('name');
            var radioGroup1 = $(this).parent().parent().find('input[name="'+groupName+'"]');
            for (i = 0; i < radioGroup1.length; i++){ 
              radioGroup1[i].checked = false;
            }
            radioGroup1.change();
          });
        });
      }; 
      //repeat the procedure when the add-button is clicked
      $('.button_search').click(function(){
        Display_Undo_Buttons_In_Column(3);
        Display_Undo_Buttons_In_Column(5);
        Display_Undo_Buttons_In_Column(7);
        UndoRadio();
      });
      //and run the procedure when the doc is loaded
      Display_Undo_Buttons_In_Column(3);
      Display_Undo_Buttons_In_Column(5);
      Display_Undo_Buttons_In_Column(7);
      UndoRadio();
    });
    </script>
  • haenselhaensel Posts: 570 ✭✭
    Hi Gerben

    That is indeed an often requested feature.

    Regards,
    Christian
  • lindsay.stevenslindsay.stevens Posts: 402 ✭✭✭
    via Email
    Impressive - you guys must really love radios to do all that :)

    Glad we still have the "single-select with an uncoded default" trick.






    $.noConflict();

    jQuery(document).ready(function($){

    function Display_Undo_Buttons_In_Column(ColNo){

    $('#UndoRadio_Col').parent().parent().parent().parent().find('tbody >
    tr:visible').each(function(i){

    // only add the undo image, if it doesn't exist

    if
    ($(this).children('td:nth-child('+ColNo+')').find('.undoradio').length ==
    0){



    if
    ($(this).children('td:nth-child('+ColNo+')').children('br').length != 0){


    $(this).children('td:nth-child('+ColNo+')').children('br').last().after("Click to deselect  entry");

    }

    else{


    $(this).children('td:nth-child('+ColNo+')').children('input[type=radio]').last().after("Click to deselect  entry");

    }

    }

    });

    };

    function UndoRadio(){

    $("img.undoradio").each(function (){

    $(this).click(function (e){

    var groupName =
    $(this).parent().find('input[type=radio]').attr('name');

    var radioGroup1 =
    $(this).parent().parent().find('input[name="'+groupName+'"]');

    for (i = 0; i < radioGroup1.length; i++){

    radioGroup1[i].checked = false;

    }

    radioGroup1.change();

    });

    });

    };

    //repeat the procedure when the add-button is clicked

    $('.button_search').click(function(){

    Display_Undo_Buttons_In_Column(3);

    Display_Undo_Buttons_In_Column(5);

    Display_Undo_Buttons_In_Column(7);

    UndoRadio();

    });

    //and run the procedure when the doc is loaded

    Display_Undo_Buttons_In_Column(3);

    Display_Undo_Buttons_In_Column(5);

    Display_Undo_Buttons_In_Column(7);

    UndoRadio();

    });

  • igalchukigalchuk Posts: 8 mod
    Hi Gerben,

    I have been trying to make the script work with my grid in OpenClinica 3.5 with no luck and I don't seem to find the sample CRF you are referring to. Do you mind attaching it here?

    Thanks,
    Iryna
  • igalchukigalchuk Posts: 8 mod
    Never mind, I found it!!! thanks
  • knelausknelaus Posts: 12
    Hi Gerben,

    I have started to use a solution regardless of group/nongroup

    1)

    Goto https://github.com/jfriend00/docReady
    Where yoy will find documentation, license and the file docready.js

    2)

    Download docready.js and place the file in "includes/jmesa/"

    3)

    Place the following code in "RIGHT_ITEM_TEXT" just one time for eksampel in the first variabel (If you have more than one section repeat this step in each.)




    $.noConflict();
    jQuery(document).ready(function($)
    {
    docReady(function() {
    (function (jQuery) {
    jQuery.fn.deselectableRadioButton = function() {
    return this.each(function() {
    jQuery(this).mousedown(function () {
    jQuery(this).data('wasChecked', this.checked);
    });

    jQuery(this).click(function () {
    if (jQuery(this).data('wasChecked')) {
    this.checked = false;
    }
    });
    });
    };
    })(jQuery);
    jQuery('input[type=radio]').deselectableRadioButton();
    });
    });



    I have attached our own eksample and the docready.js as zip file

    Best regards
    Knud Nelausen

This discussion has been closed.