How to add a javascript function to mask input in Yii

Hi again everyone… :rolleyes:

Being new to Yii, I still haven’t tried

adding a javascript through clientChange methods

with jquery

to add a mask input to my textfields…

please…any example will be appreciated very much…

thanks… 8)

Use directly CMaskedTextField widget


At view:








Hi there…thnx for the suggestion…i’ll try it when i get home. :)

How can I remove the masking placeholders before saving form?

For example I enter the date in the text fields as "26-10-2010" using jQuery masking plugin, but I want to save it to the database as "26102010".

Let’s say my database is already designed to store simple strings without any placeholders for dates, time, etc… and I don’t want to change the columns nor (resize them) neither to edit model.php and change the validation rules etc…

Is that achievable?



Convert it at ‘beforeSave’ function (try just replace ‘-’ to blanks with str_replace function)

Then, undo conversion at ‘afterSave’ function (to keep your widget working)

Hi ricardograna

In my model I have function:

public function beforeSave()



	return parent::beforeSave();


In this function I strip address_code from 12-331 to 12331. And when I try to save form it logs errors:



But when I use berofeValidate() function in model:

public function beforeValidate()



	return parent::beforeValidate();


Now the address_code 12-331 is stripped to 12331 and I see no error, but the value form text input gets cleared:


Could You help me more with this?

Thanks in advance



Please do not ask the same question on two different threads… you already opened a topic for this problem -