Clien side validation without activerecord

As mentioned in the documentation, the way to use client side validation is by using activeform to create the form.

I have a field for file upload in my forms that I can’t create it with the activeform so I use Html::activeFileInput. Is there any way to create client side validation for my file field with yii utilities that activeform uses?


There is a typo in the title I mean client side validation without activeform

I’m not sure if I understand correctly. “Active” means that is uses model attributes that are passed to view. Why can’t you use it like that?

Edit: I’ve just read the topic. You don’t need ActiveRecord model for the form to be validated. Look at the LoginForm model from advanced project for example.

There is a typo in the topic. I’m sorry about the mistake. To use client side navigation, we have to use ActiveForm widget to generate the form. The problem is, in my case I can’t use ActiveForm and I used Html::activeFileInput to create the field.

ActiveForm widget generates the client scripts to validate form inputs, but Html::activeFileInput doesn’t generate client scripts for validation.

Could you paste here the view file?

This part is the field in the view file.

<?= Html::activeFileInput( 		



             ['id'=>'file-input-'.$uniqueId] ) 


$fileObject is the model object and $uniqueId is a random string.

I’m still wondering why can’t you invoke activeform… Anyway - I think you can manually add the js using the code from ActiveForm widget.