Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 TinymceBundle

I created an ArticleController to render a form with fields: title (text) and content (textarea), and everything works well until I add class="tinymce" to the textarea field in the template. then I get this error: 'An invalid form control with name='form[content]' is not focusable.' I followed the documentation to add the 'class' attribute and the editor renders fine in the browser, its just when I submit the form I get the error.

Any ideas what could be causing this?

{{ form_errors(form) }}

{{ form_widget(form.title) }}
{{ form_widget(form.content, { 'attr': {'class': 'tinymce' }} ) }}

{{ form_rest(form) }}

<input type="submit" />

like image 396
l3thal Avatar asked Jul 29 '11 19:07

l3thal


4 Answers

Apparently there is an issue with chrome regarding the attribute 'required = "true"'. http://code.google.com/p/chromium/issues/detail?id=45640

I added 'formnovalidate = "true"' attribute to the submit button input field and it works fine

like image 60
l3thal Avatar answered Nov 15 '22 09:11

l3thal


tinyMCE.init({
    mode : "specific_textareas",
    editor_selector : "mceEditor",
    setup : function(ed) {
          ed.onChange.add(function(ed, l) {
                  tinyMCE.activeEditor.getElement().value = tinyMCE.activeEditor.getContent();
          });
   }
});
like image 23
rura52 Avatar answered Nov 15 '22 09:11

rura52


I tried the suggestion from Musefan, and it only partly worked, but it got me experimenting.

Here's something that works for me. Tested on Firefox 10.0.1, IE9, and Chrome 17.

Where I'm setting tinyMCE.activeEditor.getElement().value = 'test' it can be any value other than ''. Not sure why that's true.

tinyMCE.init({
    mode : "specific_textareas",
    editor_selector : "tinymce",

    setup : function(ed)
    {
        // This is needed when the textarea is required for html5
        ed.onInit.add(function(ed)
        {
                      tinyMCE.activeEditor.getElement().value = 'test'
        });
    },

});
like image 2
Mitchell Avatar answered Nov 15 '22 10:11

Mitchell


The error happens when the WYSIWYG hides your textarea but the textarea is set to required field. You can set 'required' => false on your content textarea control when you build the form in order to disable browser's required check.

$builder->add("content", "textarea", array('required' => false));
like image 1
mask8 Avatar answered Nov 15 '22 08:11

mask8