THIS QUESTION IS NOT ABOUT HOW TO SET DEFAULT VALUE OF A WIDGET
Hello Symfonians!
I had a fundamental doubt about forms, Im putting 2 scenarios below.
I have a customModelForm that extends a modelForm.
1> If I do not specify a default value for a form field
new: field is empty
edit: field shows the value in the object
2> If I specify a default value for a field,
new: field shows default value
edit: field shows default value
I am trying to avoid the EDIT mode behaviour in scenario 2.
The default value should only be displayed when the value in the object is not set.
I am calling parent::configure after setting the default value. Do we have any control on the ‘bind’ event?
Thanks
This shouldn’t be happening, at least in Doctrine. The part of the code where this is happening is in
updateDefaultsFromObjectinsfFormDoctrine. The relevant lines are:updateDefaultsFromObjectdoes net get called until the entire configure chain is done, so something else must be going on here.Are you using Doctrine? Are you using the most current version of Symfony (there was a bug here a while ago)? Are you sure the default is getting set in the
configuremethod of your form?The
isNewcheck richsage is recommending should be avoided. There is a larger issue here as the proper behavior is for default value to get overwritten by an existing object’s values.