Created
May 3, 2014 16:14
-
-
Save richardW8k/7cd3a3f6b0ce99a4c83d to your computer and use it in GitHub Desktop.
To convert a list field column to use checkboxes add the php excluding the first line to your theme functions.php file. The JavaScript can be placed between script tags in a HTML field on the form.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// format: gform_column_input_content_FORMID_FIELDID_COLUMN | |
add_filter( 'gform_column_input_content_524_2_2', 'change_column_to_checkbox', 10, 6 ); | |
function change_column_to_checkbox( $input, $input_info, $field, $text, $value, $form_id ) { | |
$input_field_name = "input_{$field['id']}[]"; | |
$tabindex = GFCommon::get_tabindex(); | |
$new_input = "<div class='ginput_container'><ul class='gfield_checkbox'>" . | |
"<li><input type='checkbox' {$tabindex} value='First Choice' /><label>First Choice</label></li>" . | |
"<li><input type='checkbox' {$tabindex} value='Second Choice' /><label>Second Choice</label></li>" . | |
"</ul><input type='hidden' name='{$input_field_name}' value='' /></div>"; | |
return $new_input; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery( '.ginput_list' ) | |
.on( 'click', 'input[type=checkbox]', function() { | |
var $cell = jQuery( this ).parents( 'td' ), | |
$checked = $cell.find( 'input[type=checkbox]:checked' ), | |
$value = '<ul>'; | |
$checked.each( function() { | |
$value = $value + '<li>' + jQuery( this ).val() + '</li>'; | |
}); | |
$value = $value + '</ul>'; | |
$cell.find( 'input[type=hidden]' ).val( ( $checked.length > 0 ) ? $value : '' ); | |
}) | |
.on( 'click', '.add_list_item', function() { | |
jQuery( this ).parents( 'tr' ).next() | |
.find( 'input[type=checkbox]' ) | |
.each( function() { | |
var $this = jQuery( this ), | |
$label = $this.next( 'label' ).text(); | |
$this.prop( 'checked', false ).val( $label ); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment