Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Populate first column of Gravity Form multi-column list and mark as readonly
<?php
/*
Dynamically populates the first column of a Gravity Form multi-column list field
REQUIREMENTS
(1) The end of the the `gform_field_value_$parameter_name` filter must match the parameter you've set to allow field to be populated dynamically
(2) The key in each row's array element must match the header you have set for the column.
*/
add_filter( 'gform_field_value_certifications', 'typewheel_prefill_certifications_list' );
function typewheel_prefill_certifications_list( $value ) {
$list_array = array(
array(
"Certificate / License" => "Aquatics or Waterfront",
),
array(
"Certificate / License" => "Medical",
),
array(
"Certificate / License" => "Horsemanship",
),
array(
"Certificate / License" => "Wilderness",
),
array(
"Certificate / License" => "Food Service",
),
array(
"Certificate / License" => "",
),
);
return $list_array;
}
/*
Sets inputs in column of Gravity Form multi-column list field as readonly
Removes icons for adding/removing rows from list field.
REQUIREMENTS
(1) Ensure you set the field ID & column number targeted in the jQuery selector
(2) Add this script to an HTML field at the start of your form
*/
<script>
jQuery(document).ready(function(){
jQuery( '.gfield_list_53_cell1' ).find( 'input, select, textarea' ).each(
function() {
if ( jQuery( this ).val() != '' ) {
jQuery( this ).prop( 'readonly', true );
jQuery( this ).css({'background':'none','border':'none','box-shadow':'none'});
jQuery( this ).attr('tabindex','-1');
jQuery( this ).parents('tr:not(:last-child)').find('.gfield_list_icons').hide();
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.