Custom Wizard Plugin

(Danny Goodall) #282

Hi @angus, I’ve extended the Custom Wizard Plugin with some dynamic (runtime) content functionality. I’m maintaining this on a fork at the moment and wanted to know if you’d be happy to take it into your master repo.

What does it do?

It allows the Wizard to present content to the user that is generated at runtime.

How does it do it?

I allow the developer to register a custom content code block which is called when the wizard is built and before being presented to the user.

I’ve followed your model of registering a step handler add_step_handler and instead allow the user to register an add_dynamic_content code block. This is called in the steps method in wizard.rb as the wizard is being built and the changed content is then presented to the user.

What is the use case?

I found myself using the same dropdown options across 6 wizards and when those dropdown options change - as they do, I needed to modify all 6 wizards. These dropdown options are also keys into other data structures so making a mistake in rekeying any of it would cause downstream issues.

What could be improved?

At the moment the dynamic content block manipulates the data structures inside the Wizard directly. i.e. I change a list within a hash inside the wizard. It would be far better to build those data structures with some higher level methods add_step_data, replace_step_data, add_dropdown_option, remove_dropdown_option, etc. It might be that I can use or lean on your existing UI code to do that.

Risks and why you might not want this in your repo

Well, if you can manipulate the data structures inside the core code then things can go bang (very loudly!) and it might add to your support issues.
If you decide you need to change the structures inside the core code then it gives everyone a headache if they’ve added dynamic content
It might also inhibit you from making such significant internal changes due to fear of regression failures

Happy to maintain this in a fork if you feel it’s not where you want to go.

Dan

1 Like

(zsean) #283

@angus thank you, that would be excellent! I’d rather use your generic version than my “hack” :wink:

0 Likes

(Angus McLeod) #284

@bletch Interesting!

I’d be happy to merge something similar to this, and I’m interested to see your code. Just a few notes:

  • The place to add a new hook of this sort would be in the builder.rb, rather than wizard.rb, like the step_handler hook.

  • There’s an existing add_wizard class method on the CustomWizard::Wizard class which could perhaps be used to achieve the same goal. You could do any runtime overrides using this. I use this in some (non-released) plugins to generate wizards from a .json file I’ve included in a plugin. I find it easier to just change this file than use the admin UI. e.g.

    CustomWizard::Wizard.add_wizard(File.read(File.join(
      Rails.root, 'plugins', 'civically-place', 'config', 'wizards', 'neighbourhood_petition.json'
    )))
    
neighbourhood_petition.json
{
  "id": "neighbourhood_petition",
  "name": "Neighbourhood Petition",
  "save_submissions": true,
  "theme":"Civically Wizards",
  "steps": [
    {
      "id": "intro",
      "key": "neighbourhood_petition.intro",
      "fields": [
        {
          "id": "tip",
          "type": "text-only",
          "image": "/images/emoji/twitter/adult/4.png",
          "key": "neighbourhood_petition.intro.tip"
        }
      ]
    },
    {
      "id": "location",
      "key": "neighbourhood_petition.location",
      "fields": [
        {
          "id": "location",
          "type": "location",
          "required": true
        },
        {
          "id": "tip",
          "type": "text-only",
          "image": "/images/emoji/twitter/adult/4.png",
          "key": "neighbourhood_petition.location.tip"
        }
      ]
    },
    {
      "id": "topic",
      "key": "neighbourhood_petition.topic",
      "fields": [
        {
          "id": "post",
          "type": "prefilled-composer",
          "key": "neighbourhood_petition.topic.post",
          "required": true,
          "min_length": 20
        },
        {
          "id": "prompt",
          "type": "text-only",
          "key": "neighbourhood_petition.topic.prompt"
        },
        {
          "id": "tip",
          "type": "text-only",
          "image": "/images/emoji/twitter/adult/4.png",
          "key": "neighbourhood_petition.topic.tip"
        }
      ]
    },
    {
      "id": "submit",
      "key": "neighbourhood_petition.submit",
      "fields": [
        {
          "id": "tip",
          "type": "text-only",
          "image": "/images/emoji/twitter/adult/4.png",
          "key": "neighbourhood_petition.submit.tip"
        }
      ]
    }
  ]
}

Make a PR and we can take it from there?

I’ve slotted it in: Custom Wizard: make nested properties available in wizard template interpolation - Work - Angus' Sandbox

1 Like

(Angus McLeod) #285

This should address this, from a usability perspective at least:

This is now addressed (cc @hellekin)

2 Likes

(Danny Goodall) #286

Thanks for the pointers @angus.

I’ll take a look at your recommendations, rework my code accordingly and will then submit a pull request.

I’ve never done one before so I might need to hand-holding nearer the time.

Cheers!

Dan.

0 Likes

(Nrsinga Dasa) #287

Hello Team

Is there a way to allow the continuation button to only show at the end of the post. I have seen a post where the terms are shown and it is quite long but buttons are at the end.

0 Likes

(Angus McLeod) #288

Hey, thanks for the report. I’ve pushed a fix for the text overflow issue.

0 Likes