ActiveInoutField with emty initial value.

What is the recommended way to use ActiveInputField with empty initial value? The call expects $model and $attribute, initializes value to the attribute’s value. I need initial blank field no meter what respected attribute actually holds. I see 2 options:

  • point to the dummy attribute that not populated through database.

  • or clear attribute value before rendering the form

Any other ‘cleaner’ options available?

thanks.

Can you explain the context where you need this? You’ve already mentioned the 2 obvious options, maybe we can find something better, if we understand what you try to do (and why).

I don’t see the point of displaying an empty input value if that attribute has some value (what will be the value of that attribute if the user leaves the form ie. cancels the input)… in my opinion you should clear the attribute value if you want to show empty attribute input…

I’ve not tested, but what if you put




$model->unsetAttributes();



in your controller/action, right after creating the model instance?

like




public function actionCreate()

{

     $model = new MyModel();

     $model->unsetAttributes();

}



this way Qiang solved the problem of empty initial values for filtering in CGridView

hope it helps!

regards!

:)