Custom Choice Labels

Instructions

Code

Filename: gpadvs-custom-choice-labels.js

/**
 * Gravity Perks // Advanced Select // Custom Choice Labels
 * https://gravitywiz.com/documentation/gravity-forms-advanced-select/
 * 
 * Instruction Video: https://www.loom.com/share/0af2758c28ba4c4fa98dc2f7950744a9
 */
gform.addFilter( 'gpadvs_settings', function( settings, gpadvs ) {
	settings.render = {
		option: function(data, escape) {
			return '<div>' + getLabel( data.text ) + '</div>';
		},

		item: function(data, escape) {
			return '<div>' + getLabel( data.text ) + '</div>';
		},
	}
	return settings;
} );

function getLabel( text ) {
	var bits = text.split( '|' );
	return `<h4>${bits[0]}</h4><p>${bits[1]}</p>`;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.