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

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 Mike Rockett
      Jumplinks for ProcessWire
      Release: 1.5.56
      Composer: rockett/jumplinks
      Jumplinks is an enhanced version of the original ProcessRedirects by Antti Peisa.
      The Process module manages your permanent and temporary redirects (we'll call these "jumplinks" from now on, unless in reference to redirects from another module), useful for when you're migrating over to ProcessWire from another system/platform. Each jumplink supports wildcards, shortening the time needed to create them.
      Unlike similar modules for other platforms, wildcards in Jumplinks are much easier to work with, as Regular Expressions are not fully exposed. Instead, parameters wrapped in curly braces are used - these are described in the documentation.
      Under Development: 2.0, to be powered by FastRoute
      As of version 1.5.0, Jumplinks requires at least ProcessWire 2.6.1 to run.
      View on GitLab
      Download via the Modules Directory
      Read the docs
      Features
      The most prominent features include:
      Basic jumplinks (from one fixed route to another) Parameter-based wildcards with "Smart" equivalents Mapping Collections (for converting ID-based routes to their named-equivalents without the need to create multiple jumplinks) Destination Selectors (for finding and redirecting to pages containing legacy location information) Timed Activation (activate and/or deactivate jumplinks at specific times) 404-Monitor (for creating jumplinks based on 404 hits) Additionally, the following features may come in handy:
      Stale jumplink management Legacy domain support for slow migrations An importer (from CSV or ProcessRedirects) Feedback & Feature Requests
      I’d love to know what you think of this module. Please provide some feedback on the module as a whole, or even regarding smaller things that make it whole. Also, please feel free to submit feature requests and their use-cases.
      Note: Features requested so far have been added to the to-do list, and will be added to 2.0, and not the current dev/master branches.
      Open Source

      Jumplinks is an open-source project, and is free to use. In fact, Jumplinks will always be open-source, and will always remain free to use. Forever. If you would like to support the development of Jumplinks, please consider making a small donation via PayPal.
      Enjoy! :)
    • By BitPoet
      As threatened in Ryan's announcement for 3.0.139, I built a little module for sliding toggles as a replacement for checkboxes. Styling of the input is CSS3 only (with all the usual caveats about older browsers), no JS necessary, and may still be a bit "rough around the edges", so to speak, since I didn't have much time for testing on different devices or brushing things up enough so I'd feel comfortable pushing it to the module directory. But here's the link to the GitHub repo for now:
      InputfieldSlideToggle
      Fieldtype and Inputfield that implements smartphone-style toggles as replacement for checkbox inputs. The visualization is CSS-only, no additional JS necessary.
      Status
      Still very alpha, use with caution!
      Features / Field Settings
      Size
      You can render the toggles in four different sizes: small, medium, large and extra large.
      Off Color
      Currently, "unchecked" toggles can be displayed either in grey (default) or red.
      On Color
      "Checked" toggles can be rendered in one of these colors: blue (default), black, green, grey, orange or red.
      Screenshots

      Some examples with checkbox label


      View all Size and Color Combinations
      Small toggles Medium toggles Big toggles Extra big toggles  









    • By Orkun
      Hi Guys
      I needed to add extended functionalities for the InputfieldDatetime Module (module is from processwire version 2.7.3) because of a Request of Customer.
      So I duplicated the module and placed it under /site/modules/.
      I have added 3 new Settings to the InputfieldDatetime Module.
      1. Day Restriction - Restrict different days based on weekdays selection (e.g. saturday, sunday) - WORKING

       
      2. Time Slots - Define Time slots based on custom Integer Value (max is 60 for 1 hour) - WORKING

       
      3. Time Range Rules per Weekday - Define a minTime and MaxTime per Weekday (e.g. Opening Hours of a Restaurant) - NOT WORKING PROPERLY

       
      The Problem
      Time Slots and Day Restriction working fine so far. But the Time Range Rules per Weekday doesn't work right.
      What should happen is, that when you click on a date, it should update the minTime and maxTime of the Time Select.
      But the change on the select only happens if you select a date 2 times or when you select a date 1 time and then close the datepicker and reopen it again.
      The time select doesn't get change when you select a date 1 time and don't close the picker.
      Here is the whole extended InputfieldDatetime Module.
      The Files that I have changed:
      InputfieldDatetime.module InputfieldDatetime.js jquery-ui-timepicker-addon.js (https://trentrichardson.com/examples/timepicker/) - updated it to the newest version, because minTime and maxTime Option was only available in the new version  
      Thats the Part of the JS that is not working correctly:
      if(datetimerules && datetimerules.length){ options.onSelect = function(date, inst) { var day = $(this).datetimepicker("getDate").getDay(); day = day.toString(); var mintime = $(this).attr('data-weekday'+day+'-mintime'); var maxtime = $(this).attr('data-weekday'+day+'-maxtime'); console.log("weekday: "+day); console.log("minTime: "+mintime); console.log("maxTime: "+maxtime); var optionsAll = $(this).datetimepicker( "option", "all" ); optionsAll.minTime = mintime; optionsAll.maxTime = maxtime; $(this).datetimepicker('destroy'); $(this).datetimepicker(optionsAll); $(this).datetimepicker('refresh'); //$.datepicker._selectDate($(this).attr("id"),date); //$.datepicker._base_getDateDatepicker(); // var inst = $.datepicker._getInst($(this)); // $.datepicker._updateDatepicker(inst); /*$(this).datetimepicker('destroy'); InputfieldDatetimeDatepicker($(this), mintime, maxtime); $(this).datetimepicker('refresh'); */ // $(this).datetimepicker('option', {minTime: mintime, maxTime: maxtime}); } } Can you have a look and find out what the Problem is?
      InputfieldDatetime.zip
       
      Kind Regards
      Orkun
    • By teppo
      This module tracks changes, additions, removals etc. of public (as in "not under admin") pages of your site. Like it's name says, it doesn't attempt to be a version control system or anything like that - just a log of what's happened.
      At the moment it's still a work in progress and will most likely be a victim of many ruthless this-won't-work-let's-try-that-instead cycles, but I believe I've nailed basic functionality well enough to post it here.. so, once again, I'll be happy to hear any comments you folks can provide
      https://modules.processwire.com/modules/process-changelog/
      https://github.com/teppokoivula/ProcessChangelog
      How does it work?
      Exactly like it's (sort of) predecessor, Process Changelog actually consists of two modules: Process Changelog and Process Changelog Hooks. Hooks module exists only to serve main module by hooking into various functions within Pages class, collecting data of performed operations, refining it and keeping up a log of events in it's own custom database table (process_changelog.) Visible part is managed by Process Changelog, which provides users a (relatively) pretty view of the contents of said log table.
      How do you use it?
      When installed this module adds new page called Changelog under Admin > Setup which provides you with a table view of collected data and basic filtering tools See attached screenshots to get a general idea about what that page should look like after a while.
      For detailed installation instructions etc. see README.md.
       


×
×
  • Create New...