TinyMCE - How do you make it the required field?

2

I'm using a TextArea field with TinyMCE for text posting and would like to know if some validation can be added so it does not accept blank values.

I have tried to add required of HTML5 , but when I try to send the post, the field does not send and also does not display the error, being filled or not.

html

<textarea type="text" name="texto"></textarea>  

tinyMCE script

  <script src="tinymce/js/tinymce/tinymce.js"></script>
   <script>tinymce.init({
        selector: 'textarea',
        height: 245,
        theme: 'modern',
        plugins: [
        'advlist autolink lists link image charmap print preview hr anchor pagebreak',
        'searchreplace wordcount visualblocks visualchars code fullscreen',
        'insertdatetime media nonbreaking save table contextmenu directionality',
        'emoticons template paste textcolor colorpicker textpattern imagetools'
        ],
        toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
        toolbar2: 'print preview media | forecolor backcolor emoticons',
        image_advtab: true,
        language : "pt_BR",
   forced_root_block : false,
   force_br_newlines : true,
   force_p_newlines : false
    });
    </script>
    
asked by anonymous 19.12.2015 / 14:03

1 answer

2

To do this I think it's not enough just to add required to HTML. You would have to create something like this:

$('#enviar').click(function(){
   if($('.requerido').val() == ''){
      alert('O textarea não pode estar em branco!');
   } else {
      // Envia dados
   }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script><textareaclass="requerido"></textarea>
<button id="enviar">Enviar</button>
    
19.12.2015 / 14:23