Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kylephillips/b1c5c89962abc78064274b233c51d912 to your computer and use it in GitHub Desktop.
Save kylephillips/b1c5c89962abc78064274b233c51d912 to your computer and use it in GitHub Desktop.
Replace input text elements in the Gravity Forms "choice" editor with textareas, form multi-line values
add_action( 'gform_editor_js', 'replaceInputsWithTextareas' );
function replaceInputsWithTextareas() {
?>
<script type='text/javascript'>
gform.addAction('gform_load_field_choices', function(field){
field = GetSelectedField();
replaceInputs(field.id)
});
jQuery(document).on('gform_load_field_settings', function(e,field){
setTimeout(function(){
replaceInputs(field.id)
}, 500);
});
function replaceInputs(field_id){
var $ = jQuery;
var choices = $('#field_' + field_id).find('.field-choice-row');
$(choices).each(function(){
var field = $(this).find('input[type="text"]').first();
var newField = '<textarea id="' + $(field).attr('id') + '" class="' + $(field).attr('class') + '">' + $(field).val() + '</textarea>';
$(field).replaceWith(newField);
});
}
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment