조건부 사용자 필드

Use case

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.

6개의 좋아요

You can have a look at GitHub - discourse/discourse-authentication-validations · GitHub 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.

6개의 좋아요

Sounds promising—would love to see more documentation around it.

For more information, please see: url to meta topic

Looks like the intention was there.

1개의 좋아요

That’s all there is, I’m afraid.

That’s boilerplate from GitHub - discourse/discourse-plugin-skeleton: Template for Discourse plugins · GitHub

2개의 좋아요

The plugin is actually pretty intuitive.

The bottom checkbox adds the authentication option.

Then populate the trigger responses that will activate the next user custom fields. In my case it is number of headsets greater than None.

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.

5개의 좋아요

It has been on my todo list for a little while… I’ll be sure to add it this week :slight_smile:

4개의 좋아요

I thought I had wrote this up already.. :sweat_smile:

I will update the repo with the meta link.

3개의 좋아요

Doh! Sorry I’d forgotten that too.

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.)

2개의 좋아요

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?

2개의 좋아요

Yes. I want all custom_user_fields that are Editable after signup to have those same rules applied on the /preferences/profile page.

I think that’s right. The same rules that are in effect on the create account modal would be in effect on the profile page.

4개의 좋아요

I think this would be a great addition. Moving the conditional field logic to the profile page should be pretty easy.

This would be a good candidate for pr-welcome, but I can also try to take a look in the next month or so.

5개의 좋아요

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.

That would be great!

4개의 좋아요

저도 비슷한 사용 사례가 있습니다! 가입 시와 가입 후 수정 가능한 사용자 필드 모두에 해당합니다. (예를 들어, 사용자가 당뇨를 앓고 있는 고양이를 키우고 있다면 고양이에 대해 더 많은 정보를 원하고, 자가 검사를 하고 있다면 그 방법을 알고 싶다는 식입니다)

(어딘가에서 특정 사용자 필드를 채우는 것을 신뢰 수준 변경의 조건으로 삼는 것에 대해 언급하는 사람을 봤는데, 온보딩에도 정말 흥미로운 아이디어일 것 같습니다!)

그 플러그인은 정말 멋진 것 같아요! 그 존재를 몰랐습니다. 만약 사용자 프로필 필드에 확장할 수 있다면, Jay의 필요는 물론 OP의 필요에도 잘 맞을 것 같습니다.

하지만 이 질문 덕분에 Pavilion의 Custom Wizard 플러그인 :mage:도 떠올랐고, 이런 시나리오에 적용할 수 있을지 궁금해졌습니다. 사용해 본 적이 없어서 그 기능을 정확히 알지는 못하지만, 조건부 설정사용자 정의 필드 관리를 할 수 있다고 나와 있긴 합니다… :thinking:

1개의 좋아요