Skip to content

Instantly share code, notes, and snippets.

@richardW8k
Created May 3, 2014 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardW8k/1c37a2fd0f4c0960db84 to your computer and use it in GitHub Desktop.
Save richardW8k/1c37a2fd0f4c0960db84 to your computer and use it in GitHub Desktop.
To convert a list field column to use a checkbox 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.
<?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 = "<input type='checkbox' {$tabindex} /><input type='hidden' name='{$input_field_name}' value=' ' />";
return $new_input;
}
jQuery( '.ginput_list' ).on( 'click', 'input[type=checkbox]', function() {
elem = jQuery(this);
elem.next('input').val(elem.is(':checked') ? 'Yes' : ' ');
}).on( 'click', '.add_list_item', function() {
jQuery(this).parent().parent().next()
.find('input[type=checkbox]').prop('checked', false)
.next('input').val(' ');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment