M
M
Maxim Lagoysky2017-10-11 16:47:32
Yii
Maxim Lagoysky, 2017-10-11 16:47:32

Do I need to use dynamic model here?

If the form has a select field in it, when you select something from the select, ajax is performed and the view is rendered with some fields. But the fields that are rendered from this model are not validated, do these fields need to be done through the dynamic model or am I just doing something wrong?
Here is the additional view itself, which is rendered with ajax

<? $form = ActiveForm::begin()?>
    <div class="row">
        <?= $form->field($model,'size',['options' => ['class' => 'input-field col s12 m4'], 'template' =>
            '{input}<label class="control-label" for="post-title">Size<span class="req"> *</span></label>{error}'])->textInput() ?>
    </div>
<? $form = ActiveForm::end() ?>

Here is the model, the size field is in an additional view and it is not validated.
class PostFormTest extends Model
{
    public $name_agent;
    public $email_agent;
    public $phone_agent;
    public $title;
    public $id_category;
    public $id_sub_category;
    public $city;
    public $price;
    public $term_price_product;
    public $term_time_post;
    public $maps;

    /*Rental for rent*/
    public $size;
    /*****************/

    public function rules(){
        return[
            [['name_agent', 'email_agent', 'phone_agent', 'title', 'id_category', 'id_sub_category', 'city', 'price',
              'term_price_product', 'term_time_post'], 'required'],
            ['email_agent', 'email'],
            ['phone_agent', 'match', 'pattern' => '/^\+\d+$/'],
            ['phone_agent', 'string', 'min' => 6],
            ['phone_agent', 'string', 'max' => 20],
            ['title', 'string', 'min' => 6, 'max' => 255],
            ['size', 'string', 'min' => 6, 'max' => 255],
            ['maps', 'safe'],
        ];
    }
}

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
M
Maxim Timofeev, 2017-10-11
@lagoy

not validated

because the output template (template) was changed. If you want Validation to work, change the template so that all the tags necessary for validation remain there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question