Skip to content

Instantly share code, notes, and snippets.

@kjohnson
Last active January 15, 2020 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjohnson/0a5e556e8b279537f17227eef42f3a3a to your computer and use it in GitHub Desktop.
Save kjohnson/0a5e556e8b279537f17227eef42f3a3a to your computer and use it in GitHub Desktop.
Caldera Forms Dynamic Processor Setting Example Use
console.log('loaded');
function myDynamicOptionsCallback(resolve, reject){
// alert('Fetching select options');
console.log('Callback start');
setTimeout(function(){
console.log('Resolving');
resolve([
{
value: 'aye',
label: 'Aye',
},
{
value: 'bee',
label: 'Bee',
},
])
}, 3000);
}
<?php
/**
* Plugin Name: CF Processor
*/
// include_once 'ui.php';
/**
* Add a custom processor for field validation
*
* @uses 'my_custom_cf_validator_processor'
*
* @param array $processors Processor configs
*
* @return array
*/
add_filter('caldera_forms_get_form_processors', function ($processors){
$processors['my_custom_cf_validator'] = array(
'name' => __('Custom Validator', 'my-text-domain' ),
'description' => '',
'pre_processor' => 'my_custom_validator',
'template' => dirname(__FILE__) . '/template.php'
);
return $processors;
});
add_action('admin_enqueue_scripts', function() {
wp_enqueue_script('kbj-cf-processor', plugin_dir_url(__FILE__) . 'callback.js', [], false, true);
});
<?php
echo Caldera_Forms_Processor_UI::config_fields( array(
array(
'id' => 'bar',
'type' => 'dropdown',
'options' => [
'aye' => 'Aye',
'bee' => 'Bee',
],
'label' => __( 'Bar' ),
),
array(
'id' => 'foo',
'type' => 'dynamic',
'label' => __( 'Foo' ),
'callback' => 'myDynamicOptionsCallback',
'options' => [ // Optional. Default options to be localized without a network request.
'foo' => 'Foo',
'bar' => 'Bar',
],
),
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment