Hi Adrian,
I need to fill a value of an extended hidden field when calling the form BadgeSettingsForm (for printing badge), so when the form submitted I can get the value of that extra field.
The value used for that extra field will come from the request calling the Print Badge (RHRegistrationsConfigBadges).
I already add the extra field to the form, and would like to initialise that field in the init of the form.
To do that, I would like to have a signal between “settings= …” and “form = BadgeSettingsForm(…setiings)” of RHRegistrationsConfigBadges.process,
that will allow me to add some settings before rendering the form.
Is that possible ? or some better suggestion to do that ?
Thanks,
I think you may be able to use the add_form_fields
signal - it gets called when a form gets instantiated, and iirc if you want to pass a default value you could just pass it as default=...
to the field you are adding there.
Already used: add_form_fields signal to create my extended field for the BadgeSettingsForm,
but I need to fill that field with a value input by users (not a default value) and that value I got it from another page before calling the Config Badge settings.
That’s why I need a way to fill that new field when instancing the BadgeSettingsForm.
What I mean is that add_form_fields
runs when the form gets instantiated. So setting the default value to whatever you have saved for the user at that point should be fine.
Ok, I see, I can use the value in the request to fill the field, but it will break the concept of separation form instantiation and request handler, because I use value in request to fill the field of the form.
(Alejandro told me to avoid that if possible).
Is that ok for you ?
I think if you shared some code it’d be easier - but to me it sounds like something that’s OK to do in a plugin, but without seeing the actual code I can’t say for sure.
I’ll do this:
def _add_field_to_badge_settings(sender, **kwargs):
return ('print_reason', HiddenField(), flask.request.form.get('print_reason',''))
which is called on connect signal add_form_fields of BadgeSettingsForm.
I don’t think that will work since the signal is supposed to return two values. Try this instead:
def _add_field_to_badge_settings(sender, **kwargs):
return 'print_reason', HiddenField(default=flask.request.form.get('print_reason', ''))
true, copy/paste error.
Thanks
But for the principle to do that assignment looks fine for you ?
for something that’s coming from a plugin that seems ok…
Ok, thanks.
Have a nice evening!