我正在插件表单中使用TinyMCE编辑器的一个实例,如果字段填写不正确,我需要突出显示编辑器(浅红色背景)。
如果我的代码评估编辑器未按要求填写,我可以添加自定义类“error”,但添加该类只会影响“Text”模式的背景,而不会影响“Visual”模式。
有没有一种方法可以通过WP选项来实现这一点?谢谢
下面是我如何声明编辑器-
/** Set up the editor arguments */
$wp_editor_args = array(
\'media_buttons\' => false,
\'textarea_rows\' => 10
);
/** Check to see if this editor is in error */
$is_error = $this->is_error_field(\'description\');
if($is_error) :
$wp_editor_args[\'editor_class\'] = \'error\';
print("\\t\\t\\t\\t".\'<label class="error custom-editor">Please enter an event description (minimum of 50 characters)</label>\'."\\n");
endif;
/** Add the editor */
wp_editor($this->options_event[\'description\'], \'description\', $wp_editor_args);
这是我正在使用的CSS,以防有人好奇-.dd-options .single-option input.error,
.dd-options .single-option textarea.error{
background-color: #FFEBE8;
border-color: red;
}
下面是我尝试过的(JS由@Kaiser建议)-/**
* PHP
*/
add_filter(\'tiny_mce_before_init\', \'initiate_tinyMCE_wordcount\');
function initiate_tinyMCE_wordcount($initArray){
$initArray[\'setup\'] = <<<JS
[function(ed){
setupcontent_callback : "myCustomSetupContent()";
}][0]
JS;
return $initArray;
}
/**
* JS
*/
function myCustomSetupContent() {
tinyMCE.getInstanceById(\'description\')
.getWin()
.document.body.style.backgroundColor = \'#FFEBE8\';
}