Last active
January 15, 2020 17:16
-
-
Save kjohnson/0a5e556e8b279537f17227eef42f3a3a to your computer and use it in GitHub Desktop.
Caldera Forms Dynamic Processor Setting Example Use
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
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); | |
} |
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
<?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); | |
}); |
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
<?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