mardi 14 avril 2015

Datagrid inside a datagrid, how to get the data from the form?

enter image description here


I have datagrid field inside of a datagrid field (Collective.z3c.form.datagridfield)


It works from from a front end standpoint. However, when I submit the form the received data is as follows:



'questions': [{'choices': [], 'questionContent': u'Question 1 ', 'typeOfQ': None}]


Choices is the 2nd datagrid which is returned as an empty array. Is there a better to have a n number of questions with n number of choices inside? I don't know enough about subforms or widgets to know if creating either would be a solid option.


Here is the code:



class ITableRowSchema(form.Schema):
solution = schema.Bool(
title=u'Correct Answer?', required=False,
)
trueFalse = schema.Choice(
title=u"True or False",
values=[('False'),('True')],
default=('False'),
required=False,
)
choice = schema.Text(title=u"What are the possible choices?",required=False)


class IQuestionSchema(form.Schema):
questionContent = schema.Text(
title=u"What is the question?",
required=False
)

typeOfQ = schema.Choice(
title=u"Question Type",
values=[('True/False'),('Multiple Choice'),('Multiple Select'),('Fill-in-the-Blank'),('Short Answer')],
required=False
)

form.widget(choices=DataGridFieldFactory)
choices = schema.List(title=u"Choices", required=False,
value_type=DictRow(title=u"Choice #", schema=ITableRowSchema))

class IAddContent(model.Schema):
form.widget(questions=BlockDataGridFieldFactory)
questions = schema.List(title=u"8. Create Knowledge Quiz", required=False,
value_type=DictRow(title=u"Questions", schema=IQuestionSchema))


I am working with: python, z3c.forms, plone


Aucun commentaire:

Enregistrer un commentaire