Jump to content
BitPoet

FormBuilderMultiplier - repeatable Fieldgroups in FormBuilder forms

Recommended Posts

I'm really in love with FormBuilder, but the one thing missing to match all my end users' expectations were repeatable field groups. Think repeaters, in ProcessWire terms. Our primary application of PW is our corporate intranet, so "lines" of fields are quite common in the forms I build. We have all kinds of request forms where the information for a varying number of colleagues needs to be entered (from meal order to flight booking request) and where it is simply impractical to send a form for each, and I don't want to clutter my forms with multiple instances of fields that may only get used ten percent of the time.

That's why I started to build FormBuilderMultiplier (link to GitHub).

What it does:

  • Adds an option to make a regular Fieldgroup repeatable
  • Lets you limit the number of instances of a Fieldgroup on the form
  • Adds an "Add row" button the form that adds another instance of the Fieldgroup's fields
  • Adds a counter suffix at the end of every affected field's label
  • Stores the entered values just like regular fields
  • Makes the entered values available in preview and email notifications
  • Supports most text based fields, textareas and selects (really, I haven't had enough time to test all the available choices yet)

What it doesn't do (yet):

  • Support saving to ProcessWire pages (i.e. real Repeaters)

I haven't tested all the validation stuff, Date/Time inputs etc. yet, but since I'm utterly swamped with other stuff at work, I didn't want to wait until I have it polished. Any feedback is welcome. There might also be some issues with different output frameworks that I haven't encountered yet. The forms I work with mostly use UIKit.

Status:

Still alpha, so test well before using it in the field.

Known issues:

When rows are added, the form's iframe needs to be resized, which isn't completely clean yet.

How it works:

The Fieldgroup settings are added through regular hooks, as is the logic that adds the necessary field copies for processing the form and displaying previews.

"Multiplied" field instances are suffixed with _NUM, where NUM is an incremental integer starting from 1. So if you have add two fields named "surname" and "givenname" to a fieldgroup and check the "multiply" checkbox, the form will initially have "surname_1" and "givenname_1" field (I'm still considering changing that to make the risk to shoot oneself into the foot by having a regular "surname_1" field somewhere else in the form less likely).

When a "row" is added, the first row is cloned through JS and the counter in the fields' IDs, names and "for" attributes as well as the counter in the label are incremented before appending the copies to the Fieldset container in the form.

To keep backend and frontend in sync, a hidden field named [name of the fieldset]__multiplier_rows is added to the form. Both the backend and the frontend script use this to store and retrieve the number of "rows".

ToDo:

  • Naturally, add the option to store the data in real repeaters when saving to pages.
  • Do a lot of testing (and likely fixing).
  • Make a few things (like the "Add row" button label etc.) configurable in field(set) context.
  • Add a smooth API to retrieve the multiplied values as WireArrays.

The mandatory moving screenshot:

FBMulitplier.gif

  • Like 13

Share this post


Link to post
Share on other sites

Hey! Sounds great!
I was looking for something like this for a client migration to PW for a long time.

I will check it out.

Share this post


Link to post
Share on other sites
20 hours ago, Peter Knight said:

Are there plans to also allow multipliers on the front end?

Thanks. I'm not completely sure if I read your question right. The screencap above shows the front end form (it's just included in the backend interface on the preview tab, but it's the same as if you embed your form anywhere on the frontend).

  • Like 1

Share this post


Link to post
Share on other sites

Hi @BitPoet,

I have tried your module and ran into a few error:

1. The "multiplied" rows are not getting the _NUM suffic for name and ID. Only on the label its adding #2

2. And Fatal error is thrown when checking the entries. This is within the ToPopulate function. If I Escape this row the error is gone. (I'm on the latest dev PW version)  

//$hid->label = _("Number of rows");

3. When I can view the data in entries -> the multiplier doestn have a value and the orginal has the filled in value of the original. Probably caused by 1. 
 

Share this post


Link to post
Share on other sites
1 hour ago, DL7 said:

I have tried your module and ran into a few error

Hi @DL7,

thanks for the feedback. I'll try to find the time tomorrow to give it a spin on the latest PW version so I can hopefully reproduce the behavior.

Share this post


Link to post
Share on other sites

Hi @BitPoet,

Thanks! Some additonal pointer: on an older version (3.0.36) I dont see this fatal error, but the increment still isnt working. 

The below mentioned isnt working for me either on this older version. See the form initially starts with their "normal" ID/Name as been set in the settings

On 11/12/2018 at 7:54 PM, BitPoet said:

the form will initially have "surname_1" and "givenname_1" field

This works only if I add 

if($child->name) $child->name .= "_1";

If I do this, then the increment is working perfectly. Problem I face then is that none of the entries fields are filled with values 🙂 I'm also looking into that. Fixed that by adding this same line to the populate hook:

if($child->name) $child->name .= "_1";

 

Share this post


Link to post
Share on other sites

@BitPoet One additional error I see: when using embed methode c, the JS is not triggered, this posting the form when clicking on add row. I'm checking it currently but havent found the problem yet. 

Added this the init

		$this->addHookAfter('Page::render', $this, 'addScripts');

This as a function


    public function addScripts($event) {
		$page = $event->object; 
		if($page->template == 'admin') return;
        $additionalHeadScripts = '<script type="text/javascript" src="'.wire('config')->urls->siteModules.'FormBuilderMultiplier/FormBuilderMultiplier.js"></script>';
		$event->return = str_replace("</head>", $additionalHeadScripts.'</head>', $event->return); 
	}
	

And commented/removed the current JS append to get this fixed. 

Share this post


Link to post
Share on other sites

Hi @BitPoet ,

I tried your module but have a few concerns about it. The field type Fieldset created for the forms works fine while trying out in the Preview section but on the frontend the Add Row button submits the form, I couldn't find event listeners on submit of the Add Row button to add the created Fieldset.

I'm currently using the module on ProcessWire 3.0.123.

Share this post


Link to post
Share on other sites
3 hours ago, Rajesh Khanna said:

I tried your module but have a few concerns about it. The field type Fieldset created for the forms works fine while trying out in the Preview section but on the frontend the Add Row button submits the form, I couldn't find event listeners on submit of the Add Row button to add the created Fieldset.

I'm currently using the module on ProcessWire 3.0.123.

Sounds like the FormBuilderMultiplier.js script isn't loaded. Which embed method do you use for your form?

Share this post


Link to post
Share on other sites
20 minutes ago, Rajesh Khanna said:

I have used the Template embed method.

Thanks for the quick feedback,the  template embed method should work. Is your module, by any chance, installed in a directory named differently than FormBuilderMultiplier inside site/modules? If yes, updating to the latest dev version should solve the issue.

Share this post


Link to post
Share on other sites
12 minutes ago, BitPoet said:

Thanks for the quick feedback,the  template embed method should work. Is your module, by any chance, installed in a directory named differently than FormBuilderMultiplier inside site/modules? If yes, updating to the latest dev version should solve the issue.

No the module is named properly as you stated.

Share this post


Link to post
Share on other sites
Just now, Rajesh Khanna said:

No the module is named properly as you stated. 

What FormBuilder version do you use?

I'll try to set up a test environment to see if I can replicate the issue.

Meanwhile, do you see any errors in the browser's developer console?

Share this post


Link to post
Share on other sites
3 minutes ago, BitPoet said:

What FormBuilder version do you use?

I'll try to set up a test environment to see if I can replicate the issue.

Meanwhile, do you see any errors in the browser's developer console?

Thank you for your help!!

FormBuilder version is 0.3.2 and FormBuilder Fieldset Multiplier version is 0.0.6 .

I even tried the Custom embed method, but still can't see any event listener on the Add button.

In the console, I found this line "ReferenceError: $ is not defined FormBuilderMultiplier.js:5:1 " don't know what this is.

Share this post


Link to post
Share on other sites
4 minutes ago, Rajesh Khanna said:

In the console, I found this line "ReferenceError: $ is not defined FormBuilderMultiplier.js:5:1 " don't know what this is. 

Ah, now I see. The script is missing the JQuery library (which is present in the backend).  For a short term solution, it should be sufficient to add the following lines within the <head> section of your template:

<?php $jq = $modules->get('JqueryCore'); ?>
<script src='<?php echo $config->urls->JqueryCore . "JqueryCore.js" ?>'></script>

I'll see about either making sure that jquery gets loaded by my module or rewriting the module script so it works without jquery in the long run.

  • Like 1

Share this post


Link to post
Share on other sites
18 hours ago, BitPoet said:

Ah, now I see. The script is missing the JQuery library (which is present in the backend).  For a short term solution, it should be sufficient to add the following lines within the <head> section of your template:


<?php $jq = $modules->get('JqueryCore'); ?>
<script src='<?php echo $config->urls->JqueryCore . "JqueryCore.js" ?>'></script>

I'll see about either making sure that jquery gets loaded by my module or rewriting the module script so it works without jquery in the long run.

Hi @BitPoet ,

I added the script within the <head> section and it worked. It'll be better if the jQuery gets loaded directly by the module.

Thanks a lot for your help, Cheers!!

  • Like 1

Share this post


Link to post
Share on other sites

Hi @BitPoet ,

I had another question to ask, how can I add the "multiplyLimit" function in the frontend. I have an input field where the user can add the number of input fields he/she wants to populate. Do check the attachment for reference.

multiplyLimit.png

Share this post


Link to post
Share on other sites
6 hours ago, Rajesh Khanna said:

I had another question to ask, how can I add the "multiplyLimit" function in the frontend. I have an input field where the user can add the number of input fields he/she wants to populate.

You can do that in an onchange handler for your number input. The limit is stored in the data-multiplier-limit of a hidden input with an ID of "Inputfield_" plus the name of the fieldset and "__multiplier_rows". If, for example, your "No Of Users" field is named "usercount", adding this snipped at the bottom of your template should do the trick:

<script>
$('#Inputfield_usercount').on('change', function(evt) {
  var newlimit = $(this).val();
  $('Inputfield_myinputs__multiplier_rows').data('multiplier-limit', newlimit);
});
</script>

This is untested, though. I'm heading out in a minute, but I'll take a closer look tomorrow. Did you add the "myinputs__multiplier_rows" label yourself? If not, then I missed to include the code to properly hide InputfieldHiddens in the module and need to fix that.

  • Like 1

Share this post


Link to post
Share on other sites

Hi BitPoet, thank you for that module, I'm quite happy cause I just recognized that it's not possible to use a multiplierfield in formbuilder forms – so your solution looks promising. I tried it with a single textfield and it works as expected. Except if the form validation forces the form to load again. Than the multiplier fields get messed up (cloned again) – and after a second submit error the fields are empty. 
Is this maybe related to a version conflict or is the repopulation after submit-errors just not implemented?

  • ProcessWire: 3.0.123
  • FormBuilder 40/ states 39(?), 
  • FormBuilder Fieldset Multiplier 0.0.6
  • Form embed used: template embed (option B)

Thanks for any help or hint…

fb_mpfs_1.png

fb_mpfs_2_submiterror.png

fb_mpfs_3_submiterror.png

Share this post


Link to post
Share on other sites

Great addition to FB, thanks @BitPoet

Small problem when using FB40a with PW3.0.145 to remember form entries in a cookie. On revisiting the form displays the number of rows I've added but they're empty of data.

Share this post


Link to post
Share on other sites
On 11/7/2019 at 4:28 PM, sz-ligatur said:

Except if the form validation forces the form to load again. Than the multiplier fields get messed up (cloned again) – and after a second submit error the fields are empty. 
Is this maybe related to a version conflict or is the repopulation after submit-errors just not implemented?

I need to take a look at that, but unfortunately, I'm not hopeful that I'll find enough time this week. Next week should be a bit less crazy though.

10 hours ago, psy said:

Small problem when using FB40a with PW3.0.145 to remember form entries in a cookie. On revisiting the form displays the number of rows I've added but they're empty of data.

I haven't found the time to update to the latest FB release, but it looks like soon will be a good time to do so 🙂 Stay tuned.

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
    • By ukyo
      FieldtypeFontIconPicker
      Supported Icon Libraries
      FontAwesome 4.7.0 Uikit 3.0.34 IonicIcons 2.0.1 Cahangelog
      NOTE: Module store data without prefix, you need to add "prefix" when you want to show your icon on front-end, because some of front-end frameworks using font-awesome with different "prefix".
      Module will search site/modules/**/configs/IconPicker.*.php and site/templates/IconPicker.*.php paths for FieldtypeFontIconPicker config files.
      All config files need to return a PHP ARRAY like examples.
      Example config file : create your own icon set.
      File location is site/configs/IconPicker.example.php
      <?php namespace ProcessWire; /** * IconPicker : Custom Icons */ return [ "name" => "my-custom-icons", "title" => "My Custom Icon Set", "version" => "1.0.0", "styles" => array( wire("config")->urls->templates . "dist/css/my-custom-icons.css" ), "scripts" => array( wire("config")->urls->templates . "dist/js/my-custom-icons.js" ), "categorized" => true, "attributes" => array(), "icons" => array( "brand-icons" => array( "title" => "Brand Icons", "icons" => array( "google", "facebook", "twitter", "instagram" ) ), "flag-icons" => array( "title" => "Flag Icons", "icons" => array( "tr", "gb", "us", "it", "de", "nl", "fr" ) ) ) ]; Example config file : use existing and extend it.
      File location is site/configs/IconPicker.altivebir.php
      <?php namespace ProcessWire; /** * IconPicker : Existing & Extend */ $resource = include wire("config")->paths->siteModules . "FieldtypeFontIconPicker/configs/IconPicker.uikit.php"; $url = wire("config")->urls->templates . "dist"; $resource["scripts"] = array_merge($resource["scripts"], ["{$url}/js/Altivebir.Icon.min.js"]); $resource["icons"]["flag-icons"] = [ "title" => "Flag Icons", "icons" => array("tr", "en", "fr", "us", "it", "de") ]; $resource["icons"]["brand-icons"]["icons"] = array_merge($resource["icons"]["brand-icons"]["icons"], array( "altivebir" )); return $resource; After you add your custom config file, you will see your config file on library select box. Library Title (Location Folder Name).

      If your library categorized and if you have categorized icons set like uikit and fontawesome libraries, you will have category limitation options per icon field or leave it empty for allow all categories (default).

      Example : output
      if ($icon = $page->get("iconField")) { echo "<i class='prefix-{$icon}' />"; } MarkupFontIconPicker Usage
      // MarkupFontIconPicker::render(YourIconField=string, Options=array) echo MarkupFontIconPicker::render($page->YourIconField, [ 'prefix' => 'uk-icon-', // Icon class prefix, if you have different prefix, default is : "fa fa-" 'tag' => 'span', // Icon tag default is : "i" 'class' => 'fa-lg', // If you have extra cutom classes, for example : icons sizes, Array or Sting value 'style' => 'your custom styles if you have' // Array or String Value ]); Theme support

      Search support

      Category support

       
×
×
  • Create New...