• Hello:

    I need to use different checkboxes as exclusive. I need they funcion as a group of radiobuttons. I can`t use radiobuttons because there is a problem with them. It’s impossible to work with it’s calculation field. So I am forced to use checkboxes to work with that field.

    Anyone knows if it’s possible to do it?

    Thank you very much.

    Francesc

Viewing 1 replies (of 1 total)
  • Thread Starter francescjp

    (@francescjp)

    I have looking through internet. I think an approximate solution could be something like this code? I have cut and pasted parts of code.

    Putting the next code in the following function inside functions.php?

    
    //function begins
    function wpb_hook_javascript() {
        ?>
            <script>
               jQuery(document).on('cf.form.init', function (event, data) {
    	   var state = data.state;
    	   //runs whenever a field of this form id enabled
    	   state.events.attatchEvent( 'cf.checked',  function(fieldIdAttr,formIdAttr){
              //check if the other checkboxes are cheked. If they are, uncheck them
               <blockquote>$('body').delegate('.myradio', 'click', function (e) {
               var $element = $(this)[0];
    
               if ($(this).prop('checked') == false) {
                  $(this).prop('checked', true);
                  return;
               }
    
               $('.myradio').each(function () {
                  if ($(this)[0] !== $element)
                    $(this).prop('checked', false);
                  }
               );
               });</blockquote>
    	}
        );
            </script>
        <?php
    }
    add_action('wp_head', 'wpb_hook_javascript');
    • This reply was modified 5 years, 7 months ago by francescjp.
Viewing 1 replies (of 1 total)
  • The topic ‘Use checkboxes as exclusive’ is closed to new replies.