How to define Focus in jhtmlarea?

Asked

Viewed 218 times

0

I’m getting error using the plugin Jhtmlarea:

An invalid form control with name='Description' is not focusable.

HTML

<div style="float: left; width:60%; padding:0; margin:0 auto;">  
    <h1 style="text-align:center; width:100%"">Descrição do assunto</h1><br />
    <textarea name="descricao" id="descricao" cols="60" rows="15"></textarea><br /> <br />
</div>

jQuery:

$(document).ready(function() {

  $("#descricao").htmlarea();

  $("#contato").on("submit", function (){
      if($("iframe").val().trim() == "")   {
          alert("Preencha a descrição do e-mail");
          $("#descricao").prop("required",true);
      } else {    
          $("#descricao").prop("required",false);
      }  
  });

Where am I going wrong?

To jhtmlarea is working, but I can’t stop sending with the empty description field nor put the focus on it for filling.

Where am I wrong? Vale remember that the plugin creates a iframe and makes the textarea display: none.

  • add required to the plugin. that’s the problem. I’ve already put the link d plugin.

  • No, it’s really lack of attention. But I fixed it here. But I still can’t put Focus() in jhtmlarea.

  • Are you having trouble validating or just playing the field focus

  • Both. In fact, when the plugin enters the scene, it hides the textarea and displays an iframe on top. Only, if you have nothing filled in I can’t send an alert and in that case it shows no error or nothing to the user, just do not submit the form

  • Managed to solve the problem?

  • I thought I had got as answer I gave below. But it did not work!

Show 1 more comment

4 answers

0

If an input is "required", the form will be invalid and cannot send. Focus case, if input is hidden, will not be able to focus.

  • The colleague, sorry. While you answered was editing the question, Take a look again doing favor!

  • Now that I’ve seen. If an input is "required", the form will be invalid and cannot send. The focus case, if the input is hidden, will not be able to put focus.

  • The field is not hidden and has not required in the field because I do not know who to put the required, whether in the textarea or jhtmlarea. But none worked.

  • required must be placed in the textarea.

  • yes. This is a plugin that provides word tools for editing text. Type, bold, italic, underlined. These things.

  • see this focus link: http://stackoverflow.com/questions/1615861/set-focus-to-jhtmlarea-jquery-plugin

  • I had already seen this link is not that not. I need to put the focus on an iframe that the plugin creates to overwrite the textarea and put None display on it. see: http://www.dinamicaimoveis.com.br/new/ in the contact form at the bottom of the page

  • I haven’t been able to!

Show 3 more comments

0

The field you want to validate is

<textarea name="descricao" id="descricao" cols="60" rows="15"></textarea>

So you should validate the textarea and not the iframe the library creates.

$("#contato").on("submit", function (){
  if($("#descricao").val() == "")   {
      alert("Descrição não está preenchida!");
  } else {    
      alert("Obrigado pela descrição");
  }  
});

It doesn’t work because most cases because you just have to have a break and you get the following value

<p></p><h3></h3><p></p><div><br></div><div><br></div>

So it’s not empty so it’s valid.

For Voce to be able to give Focus is the following code.:

$('#descricao').siblings().each(function(){
    if ($(this).children('iframe').length){
        var iframe=$(this).children('iframe')[0];
        iframe.contentWindow.focus();
    }
});

What I suggest is.:

$("#contato").on("submit", function (){
  var a=document.createElement('div'); //cria uma div temporaria
  $(a).html($('#descricao').val());    //insere o html na div
  if($(a).text().trim() == "")   {     //verifica apena o texto
      alert("Descrição não está preenchida!");
      $("#descricao")
         .val('')
         .prop("required",true)
      ;
      $('#descricao').siblings().each(function(){
        if ($(this).children('iframe').length){
           var iframe=$(this).children('iframe')[0];
           iframe.contentWindow.focus();
        }
     });
  } else {    
      alert("Obrigado pela descrição");
  }  
});
  • I got it. But there are two problems 1) The other fields of the form are being validated with htm5 validate and not with Javascript. So I’m putting in $("#Description"). prop("required",true); but as the plugin does display: None with the textarea, so it is not possible to focus on the textarea.

  • I edited the answer. It’s already ok?

  • Look, I narrowed down your solution and got the same result. But I still can’t validate iframe with Jscript, validate with Html5 treating the require property with true, and avoid the famous Jscript popup window. See the solution I narrowed down in my answer to the question just below! See if you can help me more!

  • You have deleted important code. With full code. It did not work?

  • gives this error: An invalid form control with name='Description' is not focusable. The plugin jHtmlArea display: None to the textarea and in this case, it is no use to do required as it will give error. I do not know any other way.

0

A practical and functional way is to create a function to check whether the field <textarea> with the plugin jHtmlArea is empty and focus on it:

function checa(){
    var a = document.createElement('div');
    $(a).html($('#descricao').val());
    if($(a).text().trim() == ""){
        alert("Vazio");
        $('#descricao').siblings().each(function(){
            if($(this).children('iframe').length){
                var iframe=$(this).children('iframe')[0];
                iframe.contentWindow.focus();
            }
        });
        return false;
    }
}

And put in your <form> the onsubmit="return checa()".

0

That worked for me.

I created a . js with this code and imported where there was jhtmlarea

  $("#contato").on("submit", function (){
    if($('#descricao').val() == "")   {     //verifica apena o texto
        alert("Descrição não está preenchida!");
        $('#descricao').siblings().each(function(){
          if ($(this).children('iframe').length){
             var iframe=$(this).children('iframe')[0];
             iframe.contentWindow.focus();
          }
       });
       return false;
    } 
  }); 

But I still can’t validate iframe with Jscript, validate with Html5 treating the require property with true and avoid the famous Jscript popup window.

  • Sweet illusion: it worked! But it stopped the rest of Jquery. Some way out?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.