Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguishable multiple SubmitButtons in the buttons attribute of a form #29

Open
moschlar opened this issue Jun 1, 2012 · 0 comments

Comments

@moschlar
Copy link
Member

moschlar commented Jun 1, 2012

I need to have multiple SubmitButtons that I need to distinguish on the server side! If they have a name attribute, their values get send in the POST request. But validation strips their values from the resulting dictionary.
Since I would like to use TurboGears @validate decorator, I would like to have some kind of trick to include the buttons in the validated data!

To reproduce the behaviour, consider the following form definition:

import tw2.core as twc
import tw2.forms as twf
import tw2.dynforms as twdf

class JudgementForm(twdf.CustomisedTableForm):

    title = 'Judgement'

    assignment_id = twf.HiddenField()
    submission_id = twf.HiddenField()

    class annotations(twdf.GrowingGridLayout):
        line = twf.TextField(size=3, validator=twc.IntValidator, css_class='span1')
        comment = twf.TextField(size=65, css_class='span4')
    comment = twf.TextArea(placeholder=u'Comment on the above source code', css_class='span5', rows=8)
    corrected_source = twf.TextArea(placeholder=u'Correct the above source code', css_class='span5', rows=8)

    buttons = [
        twf.SubmitButton('submit', name='submit', value='Submit', css_class='btn btn-primary'),
        twf.SubmitButton('reset', name='reset', value='Delete', css_class='btn btn-danger')]

If I just try it in a IPython shell, I just get:

In [4]: JudgementForm().validate({})
Out[4]: 
{'annotations': [],
 'assignment_id': '',
 'comment': '',
 'corrected_source': '',
 'submission_id': ''}

In [5]: JudgementForm().validate({'submit':'Submit'})
Out[5]: 
{'annotations': [],
 'assignment_id': '',
 'comment': '',
 'corrected_source': '',
 'submission_id': ''}

where I would like to have at least the name of the pressed button included.

Is there any way to achieve that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant