C
C
Christopher Carter2021-04-17 20:40:17
Yii
Christopher Carter, 2021-04-17 20:40:17

How to pass value from ActiveForm validation to JavaScript?

How to return a value to JavaScript from attribute validation in ActiveForm so that it can be processed?

public function validateCoupon($attribute)
{
    return 0.2;
}

As I understand that I need to dig somewhere here, but I can not find where exactly.

$('#test-form').on('afterValidateAttribute', function (event, attribute, messages) {
    console.log(messages);
});


Or is it possible in some other way? You need to process the coupon on the server and return the value (discount) to JavaScript in order to change the price, etc. Naturally, it’s stupid to do this purely within the framework of JS, since the code will be visible, here it is necessary on the server.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question