FormAlchemy drop down list not setting values

233 views Asked by At

All Im trying to do is set the values of a drop down list using a dictionary using formalchemy 1.3.5.

The documentation reads:

Methods taking an options parameter will accept several ways of specifying those options:

  • an iterable of SQLAlchemy objects; str() of each object will be the description, and the primary key the value
  • a SQLAlchemy query; the query will be executed with all() and the objects returned evaluated as above
  • an iterable of (description, value) pairs
  • a dictionary of {description: value} pairs

I create a dictionary as is described here:

Location = model.meta.Session.query(model.Location)

cityCodes = {}

for row in Location:
    cityCodes.update({row.city : str(row.location_code)})

and include it:

EmpsPerson.wiw_location_code.label('Location').dropdown(options = cityCodes),

However, the values are still being set as the description:

<option value="Dubai">Dubai</option>
<option value="Portsmouth">Portsmouth</option>
<option value="Toulouse">Toulouse</option>
<option value="Singapore">Singapore</option>

Solved:

So to fix this issue I just used:

for row in Location:
cityCodes.append([row.city,int(row.location_code)])

 EmpsPerson.location_code.label('Location').dropdown(options=cityCodes)
1

There are 1 answers

0
gawel On BEST ANSWER

I guess the doc is out of date. Try with a list