Help with PROFILE_EXTENSION_FORM

Hi,

I am trying to configure REGISTRATION_EXTENSION_FORM in our platform, to add new fields. I am on Verawood.

I forked @bryantt-v’s repository GitHub - calculquebec/custom-extra-fields: An example app for extending user profile fields in Open edX · GitHub , added it to our OPENEDX_EXTRA_PIP_REQUIREMENTS, and configured

PROFILE_EXTENSION_FORM = 'custom_extra_fields.forms.CustomExtraFieldsForm'

in openedx-common-settings. I also configured this in the django admin site configurations:

{
...
    "extended_profile_fields": [
        "wants_newsletter",
        "position",
        "research_area"
    ]
}

Now, when I try to open the Profile and the Account pages, I get errors.

In the logs, I see errors such as

lms-1  |     account_settings = get_account_settings(request, [username], view=request.query_params.get("view")): ProgrammingError(1146, "Table 'openedx.custom_extra_fields_customextrafields' doesn't exist")

Is there something else I need to do beside those two configurations ?

Mmmm, I think I am missing a “migration”. That step is not really explained in the doc as far as I could find. But it seems that tutor local do init is taking care of it.

It would be good if such step was actually documented, with the commands to run.

Ok, after running tutor local do init, I no longer have an error in the profile or account pages.

However, I also do not see the extended form in the registration page, nor on the profile or account page (where I would expect that users are able to change their answers).

Any guidance on what might be missing ?

In fact, grepping for PROFILE_EXTENSION_FORM through the code base, I find no occurence of such in any of the frontend-app repositories, only in edx-platform. Is this bit of code expected to already be usable in one or more of the frontend apps ?

Antigravity managed to write a plugin slot to use with org.openedx.frontend.profile.additional_profile_fields.v1

That makes the fields appear in the Profile page. It does not, however, add the fields at registration, which is what I was aiming to do. Any guidance for this would be appreciated.

Hi @mboisson - I’m not actually sure if this will be helpful, but I tried (and failed) to update documentation in this PR: Update docs: Adding Custom Fields to the Registration Page by sarina · Pull Request #1451 · openedx/docs.openedx.org · GitHub

I didn’t understand the review feedback on the PR so I’ve gone ahead and closed it. However if you think this documentation is helpful and want to assist in review/rewriting to get it merged, please feel free to add review comments & I can reopen it.

Hi @sarina

I had a look at your PR, and while I was missing the REGISTRATION_EXTRA_FIELDS, adding the following to my tutor plugin does not make the fields appear at registration

hooks.Filters.ENV_PATCHES.add_item(("openedx-common-settings", """PROFILE_EXTENSION_FORM = 'custom_extra_fields.forms.CustomExtraFieldsForm'"""))
hooks.Filters.ENV_PATCHES.add_item(("openedx-common-settings", """REGISTRATION_EXTRA_FIELDS['wants_newsletter'] = 'optional'"""))
hooks.Filters.ENV_PATCHES.add_item(("openedx-common-settings", """REGISTRATION_EXTRA_FIELDS['position'] = 'required'"""))
hooks.Filters.ENV_PATCHES.add_item(("openedx-common-settings", """REGISTRATION_EXTRA_FIELDS['research_area'] = 'required'"""))
hooks.Filters.ENV_PATCHES.add_item(("openedx-common-settings", """ENABLE_DYNAMIC_REGISTRATION_FIELDS = True"""))

Update, adding:

hooks.Filters.ENV_PATCHES.add_item(("openedx-common-settings", """REGISTRATION_EXTRA_FIELDS['country'] = 'required'"""))
hooks.Filters.ENV_PATCHES.add_item(("openedx-common-settings", """REGISTRATION_EXTRA_FIELDS['gender'] = 'required'"""))

does make those two fields appear to the registration form.

However, it only works for those pre-existing fields. It does not seem to work for the fields that have been added by our custom-extra-fields app.

(post deleted by author)

Digging further, I see that enabling

REGISTRATION_EXTRA_FIELDS['position'] = 'required'
REGISTRATION_EXTRA_FIELDS['research_area'] = 'required'

does actually add validation that those fields must be present in the payload…

I see that through the developer tools, the response from the server is:

{
  "position": [
    {
      "user_message": "Il vous manque un ou plusieurs champs obligatoires"
    }
  ],
  "research_area": [
    {
      "user_message": "Il vous manque un ou plusieurs champs obligatoires"
    }
  ],
  "error_code": "validation-error"
}

however it does not produce the form items in the registration page. So it makes registration impossible.

Unfortunately I don’t actually know anything about this :sweat_smile: I tried to take over a PR that someone else wrote hoping that it would be easier for them to do a PR review than writing the docs. That didn’t happen, unfortunately, and am still hoping someone who knows more than me is willing to help get the docs improved and merged.

Hi @mboisson!

This feature still needs some changes in the MFE to work properly. Please use the changes in this PR: feat: extra registration fields improvements by BryanttV · Pull Request #1669 · openedx/frontend-app-authn · GitHub .

The step-by-step instructions on what you need to configure to make it work are explained right there. However, I will also explain it here in a bit more detail:

  1. Install this Django app to use extra user fields: GitHub - BryanttV/custom-extra-fields: An example app for extending user profile fields in Open edX · GitHub . This is just an example plugin; you can also have your own plugin with your own fields. Since it has a Django model, it is necessary to run migrations.

  2. Add the following setting to your platform: (You can also use REGISTRATION_EXTENSION_FORM, however, this setting will be deprecated.)

    PROFILE_EXTENSION_FORM = "custom_extra_fields.forms.CustomExtraFieldsForm" # (This also depends on the plugin you have installed)
    
  3. Create a new site configuration in {your-lms-domain}/admin/site_configuration/siteconfiguration/add/ and add the following JSON:

    {
      "ENABLE_DYNAMIC_REGISTRATION_FIELDS": "true",
      "MFE_CONFIG": {
        "ENABLE_DYNAMIC_REGISTRATION_FIELDS": "true"
      },
      "REGISTRATION_EXTRA_FIELDS": {
        "nickname": "required",
        "birthdate": "required",
        "interests": "required",
        "wants_newsletter": "required",
        "favorite_language": "required"
      },
      "extended_profile_fields": [
        "nickname",
        "birthdate",
        "interests",
        "wants_newsletter",
        "favorite_language"
      ]
    }
    
    

With this configuration, all configured fields are required to complete the registration; however, they can be set as optional or hidden. The configuration depends on your needs.

REGISTRATION_EXTRA_FIELDS can have the following values:

  • "required" — mandatory to complete registration.
  • "optional" — it is shown but can be left empty.
  • "hidden" — it is not shown (default behavior if it doesn’t appear in the dict).

For it to work correctly with your new custom fields and save them to the DB, you must also add them to the extended_profile_fields list.

I hope this helps!

Hi @bryantt-v

The above PR does not merge on the frontend-base branch. There are just too many conflicts.

Also, @sarina, if this PR (or equivalent in frontend-base) is required, that means Verawood’s shipping of this feature is broken, doesn’t it ?

Best,

Maxime

I tried to apply the changes from your PR manually to our version of the frontend-base branch:

https://github.com/calculquebec/frontend-app-authn/compare/cq/verawood-app.dev...calculquebec:frontend-app-authn:cq/verawood-app.dev2?expand=1

It still does not display the fields.

Ok… this is wild

The extra fields do appear… and do not appear, depending on how many times I refresh the page… :exploding_head:

Here is a recording of me refreshing the page:

You can see the “Position” and “Research area” fields appear… and disappear, depending on how many times you refresh the page.

What is going on here ?!

Also, the “news letter” checkbox never appears, even though I have

hooks.Filters.ENV_PATCHES.add_item(("openedx-common-settings", """REGISTRATION_EXTRA_FIELDS['wants_newsletter'] = 'optional'"""))

it should appear but not be required to check.