BitPoet Posted November 12, 2018 Share Posted November 12, 2018 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: 16 Link to comment Share on other sites More sharing options...
Klenkes Posted November 13, 2018 Share Posted November 13, 2018 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. Link to comment Share on other sites More sharing options...
Peter Knight Posted December 9, 2018 Share Posted December 9, 2018 Looks great. Are there plans to also allow multipliers on the front end? Link to comment Share on other sites More sharing options...
BitPoet Posted December 10, 2018 Author Share Posted December 10, 2018 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). 1 Link to comment Share on other sites More sharing options...
DL7 Posted January 16, 2019 Share Posted January 16, 2019 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. Link to comment Share on other sites More sharing options...
BitPoet Posted January 16, 2019 Author Share Posted January 16, 2019 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. Link to comment Share on other sites More sharing options...
DL7 Posted January 16, 2019 Share Posted January 16, 2019 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"; Link to comment Share on other sites More sharing options...
DL7 Posted January 22, 2019 Share Posted January 22, 2019 @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. Link to comment Share on other sites More sharing options...
Rajesh Khanna Posted September 12, 2019 Share Posted September 12, 2019 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. Link to comment Share on other sites More sharing options...
BitPoet Posted September 12, 2019 Author Share Posted September 12, 2019 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? Link to comment Share on other sites More sharing options...
Rajesh Khanna Posted September 12, 2019 Share Posted September 12, 2019 @BitPoet I have used the Template embed method. <?php $form = $forms->render('demo-form'); ?> <?php echo $form; ?> This is how I have embedded the form. Link to comment Share on other sites More sharing options...
BitPoet Posted September 12, 2019 Author Share Posted September 12, 2019 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. Link to comment Share on other sites More sharing options...
Rajesh Khanna Posted September 12, 2019 Share Posted September 12, 2019 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. Link to comment Share on other sites More sharing options...
BitPoet Posted September 12, 2019 Author Share Posted September 12, 2019 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? Link to comment Share on other sites More sharing options...
Rajesh Khanna Posted September 12, 2019 Share Posted September 12, 2019 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. Link to comment Share on other sites More sharing options...
BitPoet Posted September 12, 2019 Author Share Posted September 12, 2019 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. 1 Link to comment Share on other sites More sharing options...
Rajesh Khanna Posted September 13, 2019 Share Posted September 13, 2019 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!! 1 Link to comment Share on other sites More sharing options...
Rajesh Khanna Posted September 13, 2019 Share Posted September 13, 2019 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. Link to comment Share on other sites More sharing options...
BitPoet Posted September 13, 2019 Author Share Posted September 13, 2019 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. 1 Link to comment Share on other sites More sharing options...
sz-ligatur Posted November 7, 2019 Share Posted November 7, 2019 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… 1 Link to comment Share on other sites More sharing options...
psy Posted November 11, 2019 Share Posted November 11, 2019 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. Link to comment Share on other sites More sharing options...
BitPoet Posted November 11, 2019 Author Share Posted November 11, 2019 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. 2 Link to comment Share on other sites More sharing options...
sms Posted October 2, 2020 Share Posted October 2, 2020 @BitPoet Thank you for your module! I have a small question about how to change my validation hook when fields are repeated via FormBuilderMultiplier and the name of the fields changes e.g. will be increased by number. I am getting the following notice (obviously the validation doesn't work, because the field name will not be increased with the ascending number created by FormBuilderMultiplier) Notice: Trying to get property 'value' of non-object in /.../site/templates/form-builder.inc on line 104 $forms->addHookAfter('FormBuilderProcessor::processInputDone', function($event) { $form = $event->arguments(0); if($form->name != 'tour-registration') return; $date_of_rabies_vaccination = $form->get('date_of_rabies_vaccination'); $dorv = $date_of_rabies_vaccination->value; // line 104 in form-builder.inc if($dorv > time()) { $date_of_rabies_vaccination->error(__("The date can not be in the future.")); } else if($dorv > strtotime("-21 DAYS")) { $date_of_rabies_vaccination->error(__("The date of the last rabies vaccination must be at least 21 days ago.")); } else { // vaccination date was more than 21 days ago } }); So how can I iterate resp. increment the field name in my hook? Thank you very much for your help. My environment: ProcessWire 3.0.161, FormBuilder 0.4.0 and FormBuilderMultiplier 0.0.6 Link to comment Share on other sites More sharing options...
DV-JF Posted January 28, 2021 Share Posted January 28, 2021 Hi @BitPoet , just a friendly reminder ? - Did you had a chance to look at this issue: https://github.com/BitPoet/FormBuilderMultiplier/issues/8 Perhaps you could give me some hints and I'll try to fix this problem. Many greets! Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted November 18, 2022 Share Posted November 18, 2022 Good day @BitPoet! This module doesn't seem to work with latest FormBuilder. Are you planning to maintain it and fix issues? Maybe there is already a newer version, just not in the repo? 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now