Skip to content

Conversation

@gjelsas
Copy link

@gjelsas gjelsas commented Feb 3, 2021

First implementation for a field maximum possible answers.

I would like to create a useful notice to the user, so he/she knows why his/her selection was not accepted. At the moment the survey just doesn't get saved. #124

@Pierre-Sassoulas
Copy link
Owner

Thank you for this. I think another approach would be to create a new form class called SelectMultipleLimited or something like this. See code here for SelectMultiple here : https://github.com/django/django/blob/master/django/forms/widgets.py#L744 You can probably inherit from this class and add a different clean function and a clean translated error message there.

@@ -1,54 +0,0 @@
*.*~
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep this file :)

@gjelsas
Copy link
Author

gjelsas commented Feb 3, 2021

Thank you for this. I think another approach would be to create a new form class called SelectMultipleLimited or something like this. See code here for SelectMultiple here : https://github.com/django/django/blob/master/django/forms/widgets.py#L744 You can probably inherit from this class and add a different clean function and a clean translated error message there.

You mean, not to have it just as a function, but creating an all new class? Where would that class be? That would mean to have another kind of Question.type to select from? For writing that, I would need more understanding of the code from my part... Some more hints could maybe help me getting there! Thanks!

@Pierre-Sassoulas
Copy link
Owner

Yes exactly :) Well we could add the class in https://github.com/Pierre-Sassoulas/django-survey/blob/master/survey/forms.py, then create a Question.SELECT_MULTIPLE_LIMITED value in the Question model, then we need to add this value in all the relevant list like here. The change would be a new class based on SelectMultiple and 3/4 lines of changes for handling a new question type.

@gjelsas
Copy link
Author

gjelsas commented Feb 13, 2021

I'm trying to inherit that new class from django.forms.widgets.CheckboxSelectMultiple but I do always hit a TypeError: __init__() got an unexpected keyword argument 'label' Error in django-survey/survey/forms.py, line 237, get_question_field return self.FIELDS[question.type](**kwargs) and I don't know how to avoid that. So if there is a hint or a direction to point me at, it would be greatly appreciated...

@Pierre-Sassoulas
Copy link
Owner

Apparently CheckboxSelectMultiple do not have a label argument in its constructor, you can either remove the label argument from the kwargs (del kwargs["label"]) or make a spacial case for CheckboxSelectMultiple where label could have another name.

Doc for CheckboxSelectMultiple so I don't search for it next time :D https://docs.djangoproject.com/en/3.1/ref/forms/widgets/#checkboxselectmultiple

@Pierre-Sassoulas
Copy link
Owner

Pierre-Sassoulas commented Feb 1, 2022

Closing in favor of #166 following a rebase.

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

Successfully merging this pull request may close these issues.

2 participants