acf-code_area-field
acf-code_area-field copied to clipboard
Cannot type code
Using wordpress latest + acf latest i cannot focus in the code area.

To expand on this, this happens when dynamically adding the editor, via flexible content or repeater fileds for example
Quick and dirty hack to fix this issue.
The problem is the flexible content plugin uses a temp id before assigning it with a proper id,
function create_field( $field )
{
$field['value'] = esc_textarea($field['value']);
$language = '';
switch($field["language"]){
case 'css':
$language = 'CSS';
break;
case 'javascript':
$language = 'Javascript';
break;
case 'htmlmixed':
$language = 'HTML';
break;
case 'php':
$language = 'PHP';
break;
}
echo '<textarea id="' . $field['id'] . '" rows="4" class="cm-complete-flag ' . $field['class'] . '" name="' . $field['name'] . '" >' . $field['value'] . '</textarea>';
echo '<p style="margin-bottom:0;"><small>You are writing '.$language.' code.</small></p>';
?>
<link rel="stylesheet" href="<?php echo $this->settings['dir'];?>/css/theme/<?= $field["theme"];?>.css">
<script>
jQuery(document).ready(function($){
$('.cm-complete-flag').each(function(){
var $this = $(this);
var id = $this.attr("id");
if (id.indexOf("_acfcloneindex") == -1 ){
CodeMirror.fromTextArea($this[0], {
lineNumbers: true,
tabmode: 'indent',
mode: '<?= $field["language"];?>',
theme: '<?= $field["theme"];?>'
});
$this.removeClass("cm-complete-flag");
}
});
});
</script>
<?php
}