I created a mail form within a Plone add-on which contains some fields which should only displayed (and used), if an entry in the controlpanel and the Configuration Registry has the value '1'. If this value is '0' the fields should be hidden. They should also not get into the e-mail which will be send out.
I had the following field in the controlpanel.py:
conferencefee = schema.Choice(
title=_(safe_unicode('Registration Fee?')),
description=_(safe_unicode('Have one to pay a registration fee?')),
vocabulary=yesnochoice,
required=True,
)
The vocabulary is imported from another module and looks like this:
yesnochoice = SimpleVocabulary(
[SimpleTerm(value=0, title=(u'No')),
SimpleTerm(value=1, title=(u'Yes'))],
)
Thus if the user choose 'No', the value inside the Config Registry gets an int 0 and if 'Yes' it is int 1.
I tried to use the value from the Config Registry with 'api.portal.get_registry_record('collectiveconference.conferencefee') inside the conference registration form to control, if some fields are displayed or hidden. But that didn't work so far.
I had a class RegistrationMailSchema(interface.Interface) with the field:
paymentway = schema.List(
title=_(safe_unicode('Way of Registration Fee Payment')),
description=_(safe_unicode(
'If you already payed the registration fee, please tell us, which way you used to transfer the money.')),
value_type=schema.Choice(source='PaymentOptions'),
required=False,
)
Then the adapter class class RegistrationAdapter(object) with the function:
def __init__(self, context):
(...)
self.paymentway = None
And then the class:
class RegistrationForm(AutoExtensibleForm, form.Form):
schema = RegistrationMailSchema
form_name = 'registrationmail_form'
label = _(safe_unicode('Mail To The Conference Organizer'))
description = _(safe_unicode('Register for the conference.'))
fields = field.Fields(RegistrationMailSchema, IReCaptchaForm)
fields['captcha'].widgetFactory = ReCaptchaFieldWidget
fields['paymentway'].widgetFactory = RadioFieldWidget
I want to hide the fields 'paymentway' depending on the value in the Config Registry for 'conferencefee'.
I could test the value of the Config Registry entry inside the (later in the registration form created) handleApply function and print depending on this value a specific string. But I couldn't use this if clause to control, if a field is displayed or hidden.
Thanks for any hints in advance.