F
F
freshik3122019-07-25 15:09:06
Yii
freshik312, 2019-07-25 15:09:06

Why is validator js not registering?

Good afternoon.

the form:

<?php
use frontend\widgets\ActiveForm;
use usni\library\utils\Html;

use common\modules\order\models\Order;
use cart\models\BillingInfoEditForm;
use cart\models\DeliveryInfoEditForm;
use cart\models\DeliveryOptionsEditForm;
use cart\models\PaymentMethodEditForm;

                Modal::begin([
                    'header' => '<h2>' . Ecocom::t('cart', 'One click buy') . '</h2>',
                    'toggleButton' => [
                        'label' => Ecocom::t('cart', 'One click buy'),
                        'tag' => 'button',
                        'class' => 'btn btn-success',
                    ]
                ]);
                $form = ActiveForm::begin([
                    'id' => 'oneclick-form',
                    'caption' => $this->title,
                    'enableAjaxValidation' => true,

                ]);

                $modelOrder = new Order();
                $modelBiling = new BillingInfoEditForm();
                $modelDeliverInfo = new DeliveryInfoEditForm();
                $modelDeliverOptions = new DeliveryOptionsEditForm();
                $modelPayment = new PaymentMethodEditForm();
                echo $this->render('@common/modules/cart/views/_oneclickbuy',
                    [
                        'form' => $form,
                        'modelOrder' => $modelOrder,
                        'modelBiling' => $modelBiling,
                        'modelDeliverInfo' => $modelDeliverInfo,
                        'modelDeliverOptions' => $modelDeliverOptions,
                        'modelPayment' => $modelPayment
                    ]);
                echo Html::submitButton(Ecocom::t('application', 'Continue'), ['id' => 'oneclick-but-sub', 'class' => 'btn btn-success', 'name' => 'submit-order']);

                ActiveForm::end();
                Modal::end();

Inputs:

$model = [];
$model['order'] = $modelOrder;
$model['biling'] = $modelBiling;
$model['deliverInfo'] = $modelDeliverInfo;
$model['deliverOptions'] = $modelDeliverOptions;
$model['payment'] = $modelPayment;
?>
    <!--BILING-->
<?= $form->field($model['biling'], 'email')->textInput() ?>
<?= $form->field($model['biling'], 'firstname')->textInput() ?>
<?= $form->field($model['biling'], 'lastname')->hiddenInput(['value' => '-']) ?>
<?= $form->field($model['biling'], 'mobilephone')->textInput() ?>
<?= $form->field($model['biling'], 'address1')->hiddenInput(['value' => 'guest']); ?>
<?= $form->field($model['biling'], 'city')->hiddenInput(['value' => 'guest']); ?>
<?= $form->field($model['biling'], 'country')->hiddenInput(['value' => 'UA']); ?>
<?= $form->field($model['biling'], 'postal_code')->hiddenInput(['value' => '000213']); ?>

    <!--DELIVEINFO-->
<?= $form->field($model['deliverInfo'], 'sameAsBillingAddress')->hiddenInput(['value' => true]) ?>

<?= $form->field($model['deliverInfo'], 'email') ?>
<?= $form->field($model['deliverInfo'], 'firstname') ?>
<?= $form->field($model['deliverInfo'], 'lastname')->hiddenInput(['value' => '-']) ?>
<?= $form->field($model['deliverInfo'], 'mobilephone') ?>
<?= $form->field($model['deliverInfo'], 'address1')->hiddenInput(['value' => 'guest']); ?>
<?= $form->field($model['deliverInfo'], 'city')->hiddenInput(['value' => 'guest']); ?>
<?= $form->field($model['deliverInfo'], 'country')->hiddenInput(['value' => 'UA']); ?>
<?= $form->field($model['deliverInfo'], 'postal_code')->hiddenInput(['value' => '000213']); ?>

    <!--PAYMENT-->
<?= $form->field($model['payment'], 'payment_method')->hiddenInput(['value' => 'cashondelivery']); ?>
<?= $form->field($model['payment'], 'agree', ['horizontalCssClasses' => ['wrapper' => 'col-sm-12'], 'checkboxTemplate' => "{beginWrapper}\n<div class=\"checkbox\">\n{beginLabel}\n{input}\n{labelTitle}\n" . ' <a href="#termsModal" data-toggle="modal">' . Ecocom::t('application', 'Terms and Conditions') . '</a>' . "{endLabel}\n</div>\n{error}\n{endWrapper}"])->checkbox(); ?>

Model example:

<?php
/**
 * --
 * --
 */
namespace cart\models;

use yii\base\Model;
use usni\Ecocom;
use usni\library\validators\EmailValidator;
use usni\library\modules\users\models\Address;
use usni\library\modules\users\models\Person;
use usni\library\utils\ArrayUtil;
use usni\library\modules\users\utils\UserUtil;
use common\modules\order\models\OrderAddressDetails;
/**
 * BillingInfoEditForm class file
 * 
 * @package cart\models
 */
class BillingInfoEditForm extends Model
{
    //Person fields
    public $email;
    public $firstname;
    public $lastname;
    public $mobilephone;
    public $officephone;
    //Address fields
    public $address1;
    public $city;
    public $country;
    public $postal_code;
    public $address2;
    public $state;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return array(
            //Person rules
            [['firstname', 'lastname'],         'string', 'max' => 32],
            ['email',                           'required'],
            ['email',                           EmailValidator::className()],
            ['mobilephone',                     'number'],
            //Address rules
            [['address1', 'city', 'country', 'postal_code', 'firstname', 'lastname', 'mobilephone'], 'required'],
            [['address1', 'address2'],          'string', 'max' => 128],
      [['city', 'state', 'country'],      'string', 'max' => 64],
      [['firstname', 'lastname', 'address1', 'city', 'country', 'postal_code', 'state', 'address2', 'email', 'officephone', 'mobilephone'],  'safe'],
        );
    }

    /**
     * @inheritdoc
     */
    public function attributeHints()
    {
        $person     = new Person();
        $address    = new Address();
        return ArrayUtil::merge($person->attributeHints(), $address->attributeHints());
    }
}

Problem: there is no js code that handles errors on the client side.

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