• Resolved Andrew Tegenkamp

    (@andrewteg)


    I’m reading over https://calderaforms.com/doc/autocomplete-fields/ but not finding if it’s possible to preset 2 options as selected. For example, if I have a list of drinks available, I may want to have both water and coffee as default options, with other options like tea, lemonade, juice, etc.

    Is this possible either with a filter or in the interface?

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Andrew Tegenkamp

    (@andrewteg)

    I guess a little trial and error is the thing… this seems to work if someone wants to confirm or tell of a way to use “default option” in the interface?

    
    add_filter( 'caldera_forms_render_get_field', function( $field )  {
    	if ( 'lightsaber_color' == $field[ 'slug' ]  ) {
    		//error_log(print_r($field,true));
    		$data = array('red' => 'Red', 'orange' => 'Orange', 'yellow' => 'Yellow', 'green' => 'Green', 'blue' => 'Blue', 'purple' => 'Purple', 'pink' => 'Pink', 'black' => 'Black');
    		//error_log(print_r($data,true));
    		foreach ($data AS $val => $label) {
    			$field['config']['option'][$val] = array(
    				'value' => $val,
    				'label' => $label,
    			);
    		}
    		//set a default?
    		//$field['config']['default'] = 'pink';
    		//set a lot of defaults?
    		$field['config']['default'] = array('red', 'pink');
    	}
    	return $field;
    });
    
    Plugin Author Josh Pollock

    (@shelob9)

    Thanks for using Caldera Forms. We do not support multiple defaults for any field type at this time. We are working on adding support, hopefully for 1.6.0, but that might get pushed to 1.6.1

    You can follow here:

    https://github.com/CalderaWP/Caldera-Forms/pull/2322

    Thread Starter Andrew Tegenkamp

    (@andrewteg)

    Thanks, it is working great through code, and that’s plenty good enough for me ??

    PS > I’m using the same logic of $field[‘config’][‘default’] = array() as on github there. I’ll try to look there before posting from now on!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Autocomplete Multiple Default Options?’ is closed to new replies.