Custom Wizard Plugin


(Per Torstensson) #103

Ok. New feature request which possibly is super edge case and not worth mentioning, but I thought I’d just put it here for consideration;

I will use Custom Wizard for users to post their guesses on how the World Cup group play will end. This will be pretty straight forward; 8 steps with 4 dropdown fields each which will result in a published topic, which other users can comment. Pretty neat and will work perfectly out of the box.

However, posting their guesses for the playoffs is another matter. Due to the structure of the World Cup knockout phase (e.g. 2nd in group B meets 1st in group A etc. in the round of 16), I have planned to solve this by creating;

  1. one step with 8 dropdown fields with 8 choices to select the winner of each knockout match in the round of 16
  2. a second step with 4 dropdown fields with 16 choices to select the winner of each knockout match in the quarter finals
  3. a third step with 2 dropdown fields with 32 choices to select the winner of each knockout match in the semi finals
  4. a fourth and final step with 2 dropdown fields with 32 choices to select the winner of the final and play-off for third place

This will work but with the obvious downside that the user can input contradictory results.

I am now asking if it would be possible to add functionality to load stored input values from older steps. E.g. if field_1 was stored in step_1, it would be possible to render the stored value in a later step in any title, description, label, key or value field. The syntax could be like with post builder; w{field_1}, w{field_2} etc.

If this could be implemented, I believe that I, in my very specific use case, could create the same amount of steps and dropdown fields, but with only 2 choices to select the winner of each knockout match throughout the whole playoffs. I haven’t given it much thought, but I believe there should be reasonable and relevant other use cases for this functionality as well.

Thank you for considering.


(Angus McLeod) #104

Interesting :slight_smile:

This is possible at the moment via a secondary plugin.

You can add a step handler using CustomWizard::Builder.add_step_handler that gets run after each step of a certain wizard that gives you access to all the fields of the wizard and the values submitted up to that point.

Here’s an example (this is the whole plugin).

plugin.rb

DiscourseEvent.on(:custom_wizard_ready) do
  CustomWizard::Builder.add_step_handler('wizard_id') do |builder|
    updater = builder.updater

    if builder.updater && builder.updater.step && builder.updater.step.id === 'step_id'
      input = builder.updater.fields.to_h

      if builder.submissions.empty?
        builder.submissions.push({})
      end

      builder.submissions[index_of_step]["field_id_to_fill"] = input['field_id_of_value']
    end
  end
end

(Per Torstensson) #105

Wow! Just wow! I am so hopeful for this, thank you so much for this @angus!

Trying to implement it though, I notice I am not as keen at this as I would like to be… Other than javascript for the front end and other supported plugins, this is my first foray into adding “my own” code to my installation.

I tried to be a good citizen by creating a repo (my first, sort of - yay \o/!) in which I added your code:

I then tried to add the plugin via the officially supported ways to my installation:

However, after installation it doesn’t seem to load earlier step values, and what’s more is that I can’t access the plugin section or upgrade section of the admin part of my discourse installation.

It is reasonably something obvious I am missing in the plugin.rb, but I can’t understand what - Any pointers in the right direction on what I am doing wrong installing this as a plugin is highly appreciated!


(Angus McLeod) #106

So far, you have the code I provided in the plugin.rb :+1: You need to replace the dummy values I used with the actual step and field ids.

That said, I decided I will in fact expand prefilling of fields.

Currently, fields used by actions that update the user profile are prefilled with the relevant profile field data, if it exists.

This will be generalised, so you will be able to prefill the text, textarea, dropdown and composer field types with:

  • Values from other fields; or

  • Translations with params (i.e. you could identify a field to be interpolated into the translation string); or

  • Custom text with interpolated values (i.e. like the post builder); or

  • Values in the user’s profile.

I’ll add this early next week.


#107

Is it possible to use variables in the topic title when the using the Create Topic action?

I’m using the wizard to have people fill out an application for our gaming guild, which then gets turned into a post. I was really hoping to include u{username} in the topic title so that I didn’t end up with 100 topics entitled “Application”.

(Wonderful little wizard, btw. Thank you!)


(Susan Spencer) #108

Hi @angus!
My wizard (https://forum.valentina-project.org/admin/wizards/custom/gdpr-20180521) works great for new users – it’s awesome.

But when existing users run it, the custom fields are not updated. Here’s a screenshot of my admin user account’s summary page, only ‘-’ next to the four custom fields.
https://forum.valentina-project.org/admin/wizards/custom/gdpr-20180521
Here’s a screenshot of my non-admin user account’s summary page. Data was saved from the wizard to my account:

Do you have any suggestions?

Thanks!
Susan


(Susan Spencer) #109

Hey two users reported two different responses to the custom wizard:

when I click on “Privacy Policy and FAQ, found HERE” i get the message “Sorry, you don’t have access to that topic!”

  1. “Sorry, you don’t have access to that topic!” message. No screenshot was provided. :frowning:

2.“Page doesn’t exist or is private” message. Here’s a screenshot:


(Angus McLeod) #110

Hey Susan,

Just a few questions so I can understand what’s going on:

  1. You mention a screenshot of a user account where it didn’t work? The one you’ve attached shows some custom fields with values. Could you attach the account with the issue? Thanks.

  2. What kind of fields are you using?

  3. Is the wizard required? Are the fields required? Are you sure the users the fields are not being filled for are actually filling out the fields in the wizard?

  4. What do you see in the ‘Submissions’ section for the relevant wizard?

Actually if you could PM me with a screenshot of all the settings for the wizard, the submissions and any other relevant info. Thanks.

For this one, could you also PM me the link you’re using to link users to your wizard and where it is posted. If it’s public I can test it out for myself.


(Angus McLeod) #111

I’ve made updates to this plugin to make it easier to use it for the ‘obtaining consent’ use case.

  1. You can now select User Fields by name as the target of Profile Field updates. Previously you had to know the underlying custom_field, which is difficult if you’re not familiar with Discourse.

  2. I’ve added setting, wizard redirect exclude paths, that allows you to exclude certain paths from forced wizard redirects. Currently, the paths you can exclude are admin (the default) and privacy. Additional paths can be added on request.

    An example of a ‘forced wizard redirect’ is when a wizard has an “After Time” setting enabled, which will redirect all users to the wizard at the set time.

    Excluding a path allows people to view select paths of your site while completing a wizard, even if the wizard is required or has required fields. For example, if you link to your privacy policy and want the user to read it before they complete the wizard, or check any boxes. If the user navigates away from the named path they will automatically be kicked back into the wizard.

As this applies to the GDPR, please note:

  • I’m not sure ‘consent’ is the best basis for processing most data in Discourse. It could well be ‘legitimate interests’;

  • Consent under the GDPR is meant to be granular and explicit. Getting a ‘blanket’ consent like this may not be sufficient.

See further here: How to make users to explicitly agree to ToS

Nevertheless, if you want to obtain consent for something you could use this plugin.

@slspencer These updates may help in your case (you can still PM me with the details of your setup if you need specific help).


GDPR countdown and compliance
#112

Hi,

I’ve created a new wizard to collect users website url, mobile number & email id. So in steps there are 3 fields and there is no action as I am using Save wizard submissions option.

So when I go to submissions to see the list I can see the following.

username redirect_to field_1

I don’t know why it shows redirect_to as there is no such field. And due to redirect_to I can’t see field_2 and field_3 data.

How to fix this??


(Angus McLeod) #113

redirect_to is a temporary property that is added to submission data to keep track of where to send users after they’ve completed a wizard. It shouldn’t be showing up in the Submissions section though. I’ll take a look at that.

When you say “And due to redirect_to I can’t see field_2 and field_3 data.” do you mean the Submissions table is not scrolling so you can’t see some columns?


#114

Yes, I can’t scroll through the columns as the url in the redirect_to is so long in some rows so can’t see any data from field 1 to field 3.


(Angus McLeod) #115

This will fix your issue for now.


#116

Thanks a ton. :clap::clap::clap:


(Thomas K. Running) #118

First of all, thanks a lot for the amazing work on this plugin @angus! It’s really useful! :bowing_man:‍♂️

Like many others I’m considering using this plugin for GDPR compliance and more granular user control. I’ve managed set up an action that updates two custom user fields, and that’s working great.

However, I’ve been relying on Discourse’s webhooks on user events to keep external systems up to date with the data and preferences of users in Discourse. And for some reason when user fields are updated via a Custom Wizard, no user event webhook is triggered. If I hit save in a user’s profile, it is however (as expected).

Any idea why no user event is triggered and if there’s a practical solution?


(Susan Spencer) #119

Hi @angus,
Thanks for the reply!
Here’s the screenshot for my account, there are no values in these fields & I can’t manually access the custom fields to change them.

I’ll PM you with screenshots of the wizard settings. Thanks for the assist.


(Angus McLeod) #120

You’re using the user_updated event? That will now fire when you update User Fields or other custom fields with the wizard.


(Thomas K. Running) #121

Amazing! You’re my hero, @angus! :fire::fire::fire:


(RBoy) #122

This is a brilliant and one of the most useful plugins. @sam can this be included as part of the official plugins in light of GDPR so that it shows up and is updated automatically without having to modify scripts?


(Sam Saffron) #123

I do not see how this relates to GDPR you can already set custom fields to “required” and theme the create account modal as you see fit.