Created
August 19, 2019 21:31
-
-
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
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
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