We’re working on improving the onboarding experience of our community. Naturally, we’d like to use information we know about the user to do/show certain things based on the information they give us.
Today, our users start their account creation through our OIDC integration by creating an account with our company. They provide email, name, and username to OIDC before it kicks them back over to Discourse.
The problem
We’d like to now give them some additional user fields to fill out—which is great, because Discourse offers this! Unfortunately we can’t show fields based on the responses of previous fields. For example, we’d like to ask, “What role best describes you?” with the options, developer, administrator, and analyst.
If they choose developer, I of course want to ask them what their preferred programming languages are. I will also later add them to the developer user group.
If they choose analyst, I want to ask them a different series of questions, and add them to a different user group.
Proposed solution
Many form options across the web today offer conditional form fields (e.g. where did you hear about us? if ‘other’ is selected, an additional field shows up to say why.). It would be great if you started down a similar (yet more robust) path as you have with new topic form templates, though with the added requirement of the ability to depend on another field ID, and specifically that field’s input. As an example, it might look something like this:
- type: dropdown
id: user-type
choices:
- "Developer"
- "Application Administrator"
- "Analyst"
attributes:
none_label: "Choose your role..."
label: "Which option best describes your job"
validations:
required: true
- type: dropdown
id: developer-type-programming-language
depends: user-type
choices:
- "Developer"
choices:
- "Developer"
- "Application Administrator"
- "Analyst"
attributes:
none_label: "Preferred programming language..."
label: "What is the primary programming language used in your role?"
validations:
required: true
In this example, all users would be asked the first question. If the user selects Developer from the drop-down list, then a second question would appear on the form asking what their preferred programming language is.
This conditional field improvement could be used in both the user onboarding process as well as the original intended place of new topics as well.
You can have a look at GitHub - discourse/discourse-authentication-validations which does just that, except only for the user sign up page. It doesn’t appear trivial to adopt it to the user preferences page where those fields are edited.
But you’re asking for a feature, not looking for a solution to your immediate problem.
Once populated then target the custom user fields you want to show. In my example if 1-6+ then the user will be prompted to put primary and secondary hmds.
This would be great if extended to the experimental Form-templates.
Will it be possible to have those conditions work in the user profile rather than only on the create account page? (I’m pretty sure that I understand that it’s only working on the account creation page–I have someone who wants to have people go back and enter stuff and have those rules enforced.)
Yes, this is currently the only location affected by this plugin.
Let me make sure we are on the same page:
Are you wanting the ability to update public custom user fields via /preferences/profile and we apply the same conditional hide/show logic as we do on the create an account modal?
Something like, if value of custom field 1 is show custom field 2, then show the second custom field?
Well, for you, maybe! I gave it a shot and quickly got lost. It seemed like it should be almost as easy as copying some stuff to the preferences page, but just which stuff was more than I could quickly make sense of.