MaskedInput and Validators

Hi guys.

I use MaskedInput Widget for an ip address field.




$form->field($model, 'ip_address')->widget(MaskedInput::className(), [

	    	'clientOptions' => [

	        	'alias' =>  'ip'

	    	],

		])



And i also use validator in models.




array(

                        'ip_address',

                        'app\components\validators\IpValidator',

                        'version' => 'ipv4',

                        'skipOnEmpty' => true

                ),



So its really simple. The validator in the model verifies a correct IP! The masked input widget is just a feature for the user.

The masked input widget can produce on a POST-Request following string for the field ip_address:

161.112.122.15_

And thats no valid ip address. The masked input widget doesn’t remove the traling underline.

I’ve got some other problems with the MaskedInput Widget for DecimalFormatted Numbers. But first the ip problem…

Thx.




$form->field($model, 'ip_address')->widget(MaskedInput::className(), [

    		'clientOptions' => [

        		'alias' =>  'ip',

         		'clearMaskOnLostFocus'=>true,

         		//'removeMaskOnSubmit'=>true

    		],

		])



Yii2 masked input uses Robin Herbots maked input you can look at all the options at the link if you scroll down the page.

I believe the clear moask on lost focus should do the trick if not then the removemaskonsubmit will do it but you will have to reformat it before saving if the first way doesn’t work.

You should post all of your questions at once. Someone might have not known the answer to this but your other question so in the end your just prolonging a solution to your problems.