(function(){
    {% for field_name in form.layoutable_simple_fields %}
        var field = document.getElementById('id_{{ field_name }}');

        ClassicEditor.create( field, { 
            toolbar: ['bold', 'italic', 'underline', '|', 'undo', 'redo']
        }).then(editor => {
        
            editor.model.document.on('change:data', (evt, data) => {
            
                editor.updateSourceElement();
                
                let text = editor.getData();
                if (text.length <= 0 && field.required){
                    editor.ui.element.classList.add("has-error");
                }
                else {
                    editor.ui.element.classList.remove("has-error");
                }
            });
        });
        
        
    {% endfor %}

    {% for field_name in form.layoutable_full_fields %}
        var field = document.getElementById('id_{{ field_name }}');

		ClassicEditor.create( field, {% include 'template_content/ckeditor/layout-complex.js' %}).then(editor => {
        
            editor.model.document.on('change:data', (evt, data) => {
            
                editor.updateSourceElement();
            });
        });
	{% endfor %}
})();