Yii2 modal popup - ajax validation does not work for the first time

Hello all,

I have a modal popup shown after a button click.

When the popup shows for the first time, validation does not work.

When I close it and open second time, validation works great!

What’s wrong? My JS libraries are called in this way:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script src="/assets/af535353/yii.js"></script>

<script src="/assets/af535353/yii.validation.js"></script>

<script src="/assets/af535353/yii.activeForm.js"></script>

<script src="/assets/bc9bf013/js/bootstrap.js"></script>

<script src="/js/ajax-modal-popup.js"></script> // logic to load content to popup after click

Many thanks!!!