V
V
Vladimir2017-09-05 14:37:16
Yii
Vladimir, 2017-09-05 14:37:16

Why do Yii2 js elements disappear after submitting a form?

Good day! There is a form that is submitted asynchronously using pjax. After sending, js does not fully work, and to be more precise, exactly two scripts that I noticed do not work. Here is the controller file:

public function actionIndex() {
  $model = new SimpleMails();
  if ( $model->load( Yii::$app->request->post() ) && $model->validate() ) {
    $model->save();
    if ( ! Yii::$app->request->isPjax ) {
      Yii::$app->session->setFlash( 'form_sended', '<h2 class="uppercase">Thank You!</h2><p>We will get back to you as soon as possible</p>' );

      return $this->redirect( [ 'index#thank-you' ] );
    } else {
    }
    Yii::$app->session->setFlash( 'form_sended', '<h2 class="uppercase">Thank You!</h2><p>We will get back to you as soon as possible</p>' );
    $model = new SimpleMails();
  }
  return $this->render( 'index', compact('model') );
}

Those scripts are responsible for the output of the slider (noUiSlider) and my script does not work there, as a result, some animation.
If you need more information, write in the comments, I will provide everything you need.
Tell me, what could it be? Thanks in advance for the replies!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-09-05
@MasterGerold

After the pjax update, you need to re-initialize the script that you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question