filter validator and beforeValidator not working

Hi,

I’m not sure what’s up but I’m trying to normalize input before validation and no matter what I do, a validation rule kicks in that shows that the normalization is not taking place.

Method 1: Using a "filter" Validation Rule

I’m including these rules in this order in the rules array:


[['some_attribute'], 'filter', 'filter' => function ($value) { return intval($value); }],  // (yes, I know I can just use 'filter' => 'intval')

[['some_attribute'], 'integer'],



yet for some reason, if I enter ‘1234a’ into the input field, I get “some_attribute must be an integer” as the error result in client-side validation.

Method 2: Overriding "beforeValidate":


    public function beforeValidate()

    {


        $this->some_attribute = intval($this->some_attribute);

        return parent::beforeValidate();

    }



this didn’t work either. Both methods ended up with the same result. The integer rule kicked in preventing submission of the form.

Does anyone have any ideas as to why this might be happening?

"filter" validator works only on server side.

if you want to run many validators with it in specified order,

all validators must work only on serve side.

thanks - so if I write just one custom validator (not filter) and remove any other validators from this attribute in this scenario, then client-side will work?

if "custom validator" will be "integer" yes :wink:

core validators implement javascript to work in the browser.