Hi all,
I’ve been debugging quite hard in the last few hours until I realised the flaw of my implementation and so I decided to come here to seek help from more experienced Yii users which you are
My model has got an attribute "location"
In the form I want to have a drop down list with a bunch of values that are already present in the db, but I want to give the user the ability to freely enter a new value in case it wasn’t in the list.
On creation the text field will take precedence over the drop down list.
On update the drop down will update the value if the text field will has not been touched, other wise -again- the text field will take precedence.
Now I’ve got the dropDownList and the textField in the form, which is fine, but I don’t know how to bind the two fields.
My solution (which has been proved to be faulty) is this:
the dropDownList has got its own attribute name "locationProvided"
the textField is the original one "location". (these cannot be the same as the second field will override the first one).
Now locationProvided has got setLocationProvided() and getLocationProvided() that will update location if a value has been selected.
This solution will not work, as location when is processed, will override the value setLocationProvided() has given.
If you’re still with me, the solution I’m trying to find is something that will impact nothing or less the controller and live mainly in the model (this way I could implement the solution without refactoring too much any other model that needs such thing)
A possibile alternative solution, which I haven’t tried yet, could be using an array of values for location, instead of two different attributes, but I don’t know whether that could cause any other issues.
Thanks for any suggestions that can come through.