php – yii2 displaying form validation errors

Question:

The task is to display validation errors in a placeholder

standard template for example like this

'template' => '{label} <div class="row"><div class="col-sm-4">{input}{error}{hint}</div></div>'

who knows how to solve the problem?

Answer:

You can try to solve the problem using jquery, something like this:

$(function() {
  $(".put-to-placeholder").each(function(){
    $(this).prevAll("input").attr('placeholder', $(this).text() );
  });
});
.put-to-placeholder {
  display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div>
  <input type="text" value="" class="form-control">
  <span class="put-to-placeholder">error message 1</span>
</div>

<div>
  <input type="text" value="" placeholder="2" class="form-control">
  <span class="put-to-placeholder">error message 2</span>
</div>
Scroll to Top
AllEscort