S
S
SlimSavernake2018-05-28 08:04:43
JavaScript
SlimSavernake, 2018-05-28 08:04:43

How to check the validation result on the client of a specific field in YII2?

Good afternoon. I want to show the picture the user has selected in the input file field next to this field. But only on condition that the picture has passed the built-in YII2 client-side validation. Please tell me how can I describe this condition in javascript.

if (валидация на конкретном поле пройдена ) {
     вставляем картинку.
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SlimSavernake, 2018-05-29
@SlimSavernake

$('#myForm').on('afterValidateAttribute', function(event, messages) {
  if(messages.length) {
    alert('Ошибка валидации');
    return false;
  }
})

V
Vitaly, 2018-05-28
@rim89

make an xhr request on an event - uploading a photo to the server, to the controller that is validating .. in response, the controller sends true / false , then in the response it is checked that the server answered, if true - then load the image

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question