Good day! I would like to use something like this in my form https://material.google.com/components/text-fields.html#text-fields-required-fields

In addition, the error is not displayed in the field, but next to the field in the div and is filled with ajax requests sent at the user’s input and we will not redo it.

That is, we have this markup:

<form id="regist_form" method="post" action="#"> {literal} <script> $(function(){$("#login").nickmsk({ctype:"userlogin", fsetid: 0, msg: $("#login_msg"), min: 5 });});//навешивает на поле проверку ajax на лету. Менять это не будем. </script> {/literal} <div class="form-group"> <label for="login" class="sr-only"> Email<sup>*</sup> </label> <div> <input type="email" value="" name="login" id="login" maxlength="400" class="formControl" autocomplete="off" placeholder="Введите email" autofocus/> </div> <div id="login_msg"></div> </div></form> 

It is necessary that when the user enters the text in the field and the placeholder disappears, then the label shows the value from the placeholder, otherwise the label would be hidden / empty. I would like it to work independently and do not conflict with the check on the fly. Which can insert an error into the div id = "login_msg" if the format of the mail is not correct and possible if the field is not filled.

  • It is not clear how to test your code: en.stackoverflow.com/help/mcve - m9_psy
  • change label text when getting focus and losing. Doesn't Google provide ready-made components? - Grundy
  • And why when getting focus, and not changing the field content? - htclog81

0