chriskelly / LifeFinances

Scripts for validating retirement plans using Monte Carlo analysis.
GNU Affero General Public License v3.0
9 stars 3 forks source link

Equity Target form option reset #137

Closed chriskelly closed 1 year ago

chriskelly commented 1 year ago

On the parameters page, when the equity target is adjusted in the SelectField, and the save button is used, the user object is updated correctly and the database is updated correctly, but when the form is rendered, there is no selected value, so the SelectField is always defaulted to the first option (500).

Here you can see how select fields should be rendered, as seen with the real_estate_equity_ratio. The Equity Target has no option marked as selected value though.

 \n\n\n\n\n<div class="form-group "><label class="control-label" for="real_estate_equity_ratio">Real Estate Equity Ratio</label>\n        \n          
<select class="form-control" id="real_estate_equity_ratio" name="real_estate_equity_ratio">
<option value="0.0">0.0</option>
<option value="0.1">0.1</option>
<option value="0.2">0.2</option>
<option value="0.3">0.3</option>
<option selected value="0.4">0.4</option> {# how the selected option is typically rendered #}
<option value="0.5">0.5</option>
<option value="0.6">0.6</option>
</select>\n        \n  
</div>\n\n\n    \n\n\n\n\n<div class="form-group "><label class="control-label" for="equity_target">Equity Target</label>\n        \n          
<select class="form-control" id="equity_target" name="equity_target">
<option value="500">500</option>
<option value="600">600</option>
<option value="700">700</option>
{#...etc, none are marked selected value #}
<option value="3800">3800</option>
<option value="3900">3900</option></select>\n        \n  </div>

You can see in the models.user module, that there's no difference in the SelectField creation

class UserForm(FlaskForm, ModelForm):
   real_estate_equity_ratio = SelectField(choices=User.real_estate_equity_ratio.options)
   equity_target = SelectField(choices=User.equity_target.options)
   flat_bond_target = SelectField(choices=User.flat_bond_target.options)

There is a difference in the way that the options are generated. Equity target is using a list conversion of a range rather than a direct list like all the other attributes.


class User(db.Model):
   real_estate_equity_ratio:float = SuperColumn(db.Float, nullable=False,
                                                 server_default=db.text("0.6"),
                                                 info={'label':'Real Estate Ratio'},
                                                 help_text='Ratio ...  bonds.',
                                                 options = [
                                                     0.0,
                                                     0.1,
                                                     0.2,
                                                     0.3,
                                                     0.4,
                                                     0.5,
                                                     0.6
                                                 ],
                                                 optimizable = True)
   equity_target:float = SuperColumn(db.Float, nullable=False, server_default=db.text("1500"),
                                      info={'label':'Equity Target'},
                                      help_text="When ... leverage.",
                                      options = list(range(500,4000,100)),
                                      optimizable = True)
chriskelly commented 1 year ago

Tried to switch to list comprehension of the option definition, didn't change the rendering behavior.