PloneFormGen with Multi-Select field
I'm in process creating a form in Plone/PloneFormGen. This form has Multi-Select field that I am populating from MySQL database as key,value
1, Option 1
2, Option 2
3, Option 3
etc...
开发者_JS百科
This is stored into MySQL table as an array of keys ['2', '4']
Now I want to create an editing form to edit old data. How I can get old selected options (stored in database) to be selected as a default in edit form? I have been attemting overrides with diffrent options, but nothing seems to work. I have a pythos script to extract the data, but...
Version of Plone 3.3.5 PloneFormGen 1.6.3
The Problem was not only formatting. Also string had to be converted to integers.
I solved it with a following code.
This is part of a python script, where I pull data from SQL to populate the form in PloneFormGen.
form['col_name'] = tuple(int(v) for v in re.findall("[0-9]+", row['col_name']))
This will convert comma separated string to a tuple containing integers...
Odds are that your returned data isn't actually in list form. It's probably just a formatted string. So, you'll need to use your script to convert the string to a list of values.
If your possible values are simple characters, this may be very simple: remove the brackets, spaces and quotes, then split on commas.
精彩评论