P
P
Pogran2016-07-13 12:32:13
Yii
Pogran, 2016-07-13 12:32:13

How to make validation through yiiActiveForm?

At me on page at loading of model, fields are then dynamically substituted. And so I want to add validation through yiiActiveForm directly. I write like this

jQuery('#product-form').yiiActiveForm('add', {
                            'id': 'title',
                            'name': 'title',
                            'container': '.field-contactform-title',
                            'input': '#title',
                            'error': '.help-block.help-block-error',
                            'validate': function (attribute, value, messages, deferred) {yii.validation.required(value, messages, {\"message\":\"Address cannot be blank.\"});}
                        })
                        ", \yii\web\View::POS_END);

I end up with an error like this Uncaught TypeError: Cannot read property 'attributes' of undefined. The error occurs in the add method in this line $form.data('yiiActiveForm').attributes.push(attribute);
add: function (attribute) {
            var $form = $(this);
            attribute = $.extend({value: getValue($form, attribute)}, attributeDefaults, attribute);
            $form.data('yiiActiveForm').attributes.push(attribute);
            watchAttribute($form, attribute);
        },

Can initialization what for a field should be done?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pogran, 2016-07-13
@Pogran

Solved the issue by adding $(window).on('load', function() { //code })

A
Alexander N++, 2016-07-13
@sanchezzzhak

The doc seems to have this
www.yiiframework.com/doc-2.0/guide-input-validatio...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question