Jump to content

Module: ConfigurationForm (multiple fields container)


OLSA
 Share

Recommended Posts

Hello for all,

ConfigurationForm fieldtype module is one my experiment from 2016.
Main target to build this module was to store multiple setup and configuration values in just 1 field and avoid to use 1 db table to store just single "number of items on page", or another db table to store "layout type" etc. Thanks to JSON formatted storage this module can help you to reduce number of PW native fields in project, save DB space, and reduce number of queries at front-end.

Install and setup:

  1. Download (at the bottom ), unzip and install like any other PW module (site/modules/...).
  2. Create some filed using this type of field (ConfigurationForm Fieldtype)
  3. Go to field setup Input tab and drag some subfields to container area (demo).
  4. Set "Name" and other params for subfields
  5. Save and place field to templates ("Action tab")

How to use it:

In my case, I use it to store setup and configurations values, but also for contact details, small content blocks... (eg. "widgets").

Basic usage example:

ConfigForm fieldtype "setup" has subfields:

"limit", type select, option values: 5, 10, 15, 20
"sort", type select, option values: "-date", "date",  "-sort", "sort"

// get page children (items)
$limit = isset($page->setup->limit) ? $page->setup->limit : 10;
$sort = isset($page->setup->sort) ? $page->setup->sort : '-sort';
$items = $page->children("limit=$limit, sort=$sort");

 

Screenshots:

Field setupSome page setupVariant SEO and setups fieldsCompact view option

Contact details (none compact view)Services using repeater and configform fieldtypeRepeater label as subfield value

 

Notes:

  • Provide option to search inside subfields
  • Provide multilanguage inputs for text and textarea field types
  • Provide option for different field layout per-template basis
  • Do not place/use field type "Button" or "File input" because it won't works.
  • Please read README file for more details and examples

Module use JSON format to store values. Text and textarea field types are multilanguage compatible, but please note that main target for this module was to store setup values and small content blocks and save DB space. Search part inside JSON is still a relatively new in MySQL (>=5.77) and that's on you how and for what to use this module.

Thanks:

Initial point for this fieldtype was jQuery plugin FormBuiled and thanks to Kevin Chappel for this plugin.
In field type "link" I use javascript part from @marcostoll module and thanks to him for that part.

Download:

FieldtypeConfigForm.zip

Edit: 14. August 2018. please delete/uninstall previously downloaded zip

Regards.

   
  • Like 19
  • Thanks 4
Link to comment
Share on other sites

Here are more details and some news about this module.

What's new (14. August 2018.):
- fix small bug
- search by subfields
- different layouts per-template basis

Examples:

1) 1 single field for configuration and setup instead 7 PW native fields

On "Home" administration page want to have global config options (stylesheet, development or production mode), and SEO settings fields.
On category pages need to have options to change number of children in list, provide option to select different layouts, and SEO settings fields.
Conclusion, need to have 7 fields: stylesheet (select), development (select or check), SEO fields (eg. title, description and robots), limit, layout.

Create field "setup" with all needed subfields:

field-setup-1.thumb.png.cd83abe872c74a369f22dd5087871f7e.pngfield-setup-2.thumb.png.56b8dba113a9032baaaa389d48417cec.pngfield-setup-3.thumb.png.08dc69b43a6f630ea813835cbf76d1b8.png

But also want to have different field layout inside Home and category pages.
For that we use "Compact view" inside template setup.
Result, same field but with different inputs and layouts.

layout-1.thumb.png.7f139c6063d9069d3f11c8bfe7657c6e.pnglayout-2.thumb.png.01a23e9c942401a0d8de7f5a8a69a43d.png

 

On site are dozen of categories and want to find where are used grid and where list layout.
Or, website is in still development mode and want to find NOINDEX categories, etc...


search-by-subfields-1.thumb.png.5551d4d98c4d402c3227edf550d988f0.png

 

2) Multiple different textareas on "basic-page" and "basic-page-2" templates using 1 single field
Task:
 - textarea1, textarea2 and textarea3 on basic-page template
 - textarea1, textarea4, textarea5 on basic-page-2 template
 - all that with 1 PW field

 Create field "content" with 5 textarea field types (textarea1...textarea5)
 
 Set Visibility condition like this:
 basic-page=textarea1, textarea2, textarea3
 basic-page-2=textarea1, textarea4, textarea5
 
 Inside Action tab add field to templates basic-page and basic-page-2.
 Later in page administration are only desired textarea inputs.

text-areas-1.thumb.png.636c0e7fb746c7a30f36e9c3769eb256.pngtext-areas-2.thumb.png.2296d1ffed301e4a6f8a8de684d4ef43.png

 
Search: find all pages where textarea1 contain word "Toronto"

 $items = $pages->find('content.textarea1*=Toronto');

Or in admin backend using lister:

search-by-subfields-2.thumb.png.bcffc5304210ca7f7cf3beae009a1c5c.png

In front side:

$selector = 'content.textarea1*=Toronto';
$items = $pages->find($selector);

if($items->count){
	echo "<h2>Find items: {$items->count}</h2>";
	echo "Selector:<pre>$selector</pre>";	
	foreach($items as $item){		
		echo $item->title .', template: '. $item->template->name;
		echo '<br />';
		
	}
}

search-by-subfields-3.png.9bbca688f6e31d6d649a66da5069c7cb.png

Note: this example is only for demostrations and I didn't test this in case of few thousands pages.

 

  • Like 5
Link to comment
Share on other sites

Great work! Thanks for sharing.

Unfortunately, I didn't have time yet to try this out, but I'll give it a go in the next couple of days.

I can imagine quite a few real-world usage scenarios for this.

  • Like 2
Link to comment
Share on other sites

Zdravo Sasa, kako je sunce u Crnoj Gori?  ?

I installed your module and played around a bit. Looks good so far.

Only thing I spotted: the PW width settings are not being displayed as intended, when I choose "compact view". In normal view, it's working fine.

And also, some elements are a bit too close to each other, when choosing compact view: (checkbox and radio labels)

compact-view.thumb.PNG.251c03bf1af2c8c1ad2920dffd21efdf.PNG

  • Like 1
Link to comment
Share on other sites

Dragane, odlicno, samo da je malo manje vruce ;)

CompactView is html table view and idea for that type of layout was to use it in cases where are inputs closely related (eg. some contact details), and inside repeaters because don't take too much space (can open few repeater items, and at the same time, view fields in all of them).

I missed to write in notes that PW Width value is not used inside CompactView layout.
Sorry but it's possible that I skiped to write and some other notes, and feel free to ask me anything that is not clear or confusing.

Fields what I used in almost 90% are: select, text, textarea, page and link. Radio and checkboxes very, very rarely (can't remeber), and in that case I prefer to use select.

Please can you try to add to the end of module css file (module  directory... site/modules/FieldtypeConfigForm/assets/css/admin.css) this few lines:

.CompactView .InputfieldCheckboxesStacked, .CompactView .InputfieldRadiosStacked {list-style:none;padding-left:0;}
.CompactView .InputfieldCheckboxesStacked input, .CompactView .InputfieldRadiosStacked input {margin-right:10px;}

, and after it refresh browser page (CTRL+F5) and check if it will be better?

Thanks and regards!

  • Like 3
Link to comment
Share on other sites

Yep, much better. I also removed the 12px font-size for the compact view label, it somehow looks weird to me if it's smaller than the rest, but that's just personal preference.

Thanks for clarifying that the width is ignored in compact view on purpose.

  • Like 1
Link to comment
Share on other sites

On 8/10/2018 at 7:34 AM, OLSA said:

Notes:

  • Provide option to search inside subfields
  • Provide multilanguage inputs for text and textarea field types
  • Provide option for different field layout per-template basis
  • Do not place/use field type "Button" or "File input" because it won't works.
  • Please read README file for more details and examples

May I suggest to simply exclude button and file inputs - it's kinda pointless to see them there as available input fields, when in fact they don't (yet?) work.

And the mulitlanguage part would be really really awesome. Most sites we build are multilang, so this feature would be almost a must-have, rather than a nice-to-have.

Did you post your module to the official PW module directory? https://modules.processwire.com/add/
That way, it would be easier for other people to find your module. And (afaik) this is a pre-requisite if you want people to use the "check for updates" feature in the PW-backend.

Zelim ti lep vikend ?

 

  • Like 2
Link to comment
Share on other sites

Zdravo Dragane,

I totally agree with you, and I'm aware of all imperfections, but I use it last 2 years in all my projects (multilanguage) and it's play important role in all of them.
News is that I am started with development of different version of that module and it's possible that I will include all suggestion in that version, or will do that in next release of current version, and after it post it to Github and in PW module directory.

Inputs like text and textarea are multilanguage, but labels are not because that part depends on jQuery FormBuilder plugin (in my case, I write labels in administration default language).

I really appreciate all the suggestions to make this module better and thanks for that!

  • Like 1
Link to comment
Share on other sites

Evo me opet ?

I encountered a strange problem today when I wanted to setup something with required fields:

I first hit the module's save-button, then I hit the PW field-save button. And PW can't save the field, because I get errors from the first field that is required (I don't want to prepopulate the fields or use placeholders).

This is some kind of a Catch-22 problem I guess ?

And also, I see JS errors in Chrome console:

config-errors-JS.thumb.PNG.e714fe59eff1b04f6f756b2619818c17.PNG

 

When I want to edit a page where I have this field inside, Tracy reports this error:

ErrorException: count(): Parameter must be an array or an object that implements Countable in /home/sitecom/www/mysite/site/modules/FieldtypeConfigForm/FieldtypeConfigForm.module:69
Stack trace:
#0 [internal function]: Tracy\Bar->Tracy\{closure}(2, 'count(): Parame...', '/home/zeixcom/w...', 69, Array)
#1 /home/sitecom/www/mysite/site/modules/FieldtypeConfigForm/FieldtypeConfigForm.module(69): count(Object(stdClass))
#2 /home/sitecom/www/mysite/wire/core/Wire.php(389): ProcessWire\FieldtypeConfigForm->___formatValue(Object(ProcessWire\Page), Object(ProcessWire\Field), Object(ProcessWire\ConfigForm))
#3 /home/sitecom/www/mysite/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___formatValue', Array)
#4 /home/sitecom/www/mysite/wire/core/Wire.php(413): ProcessWire\WireHooks->runHooks(Object(ProcessWire\FieldtypeConfigForm), 'formatValue', Array)
#5 /home/sitecom/www/mysite/wire/core/Page.php(1436): ProcessWire\Wire->_callHookMethod('formatValue', Array)
#6 /home/sitecom/www/mysite/wire/core/Page.php(1364): ProcessWire\Page->formatFieldValue(Object(ProcessWire\Field), Object(ProcessWire\ConfigForm))
#7 /home/sitecom/www/mysite/wire/core/Page.php(1116): ProcessWire\Page->getFieldValue('setup')
#8 /home/sitecom/www/mysite/wire/core/Page.php(1600): ProcessWire\Page->get('setup')
#9 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/panels/RequestInfoPanel.php(470): ProcessWire\Page->getFormatted('setup')
#10 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-master/src/Tracy/Bar.php(159): RequestInfoPanel->getPanel()
#11 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-master/src/Tracy/Bar.php(108): Tracy\Bar->renderPanels()
#12 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/TracyDebugger.module(1487): Tracy\Bar->render()
#13 /home/sitecom/www/mysite/wire/core/Wire.php(383): TracyDebugger->sessionHandlerDBAjaxFix(Object(ProcessWire\HookEvent))
#14 /home/sitecom/www/mysite/wire/core/WireHooks.php(825): ProcessWire\Wire->_callMethod('sessionHandlerD...', Array)
#15 /home/sitecom/www/mysite/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\ProcessWire), 'finished', Array)
#16 /home/sitecom/www/mysite/wire/core/ProcessWire.php(603): ProcessWire\Wire->__call('finished', Array)
#17 /home/sitecom/www/mysite/wire/core/ProcessWire.php(499): ProcessWire\ProcessWire->__call('finished', Array)
#18 /home/sitecom/www/mysite/wire/modules/Process/ProcessPageView.module(254): ProcessWire\ProcessWire->setStatus(16)
#19 /home/sitecom/www/mysite/wire/core/Wire.php(380): ProcessWire\ProcessPageView->___finished()
#20 /home/sitecom/www/mysite/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___finished', Array)
#21 /home/sitecom/www/mysite/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\ProcessPageView), 'finished', Array)
#22 /home/sitecom/www/mysite/index.php(56): ProcessWire\Wire->__call('finished', Array)
#23 {main}

Any ideas? Did you ever stumble across such a situation?

Edited by dragan
added Tracy Debugger error msg
Link to comment
Share on other sites

Hi Dragane,

sorry for the delayed response (I am on vacation until September 1st).

If that's  JS errors are in Chrome console inside field setup, that might be in relation with required attribute and Chrome browser (here are more details), but if you insert any values in setup "form" fields maybe you can "skip" that and PW will save field and it's subfields? Also, as a result of the first , maybe you have "empty" field (without subfields), and that cause second error (never noticed before, but I'll investigate that).

Here is one important detail that you probably didn't notice, and my fault because I didn't mention, required attribute is not in use in current version.

There are few options and buttons what are not in use and I didn't remove because my first plan was to use them all for fields (eg. "Required",  "Limit access..." ) or for new features.

Link to comment
Share on other sites

  • 4 weeks later...

Hey!
Thank you for this great module, I use it as part of a repeater item (for settings, to save some white space and grouping the settings).

Now I tried to echo the Value of a select option (Dropdown) like this:
{$item->grid_settings->gridsize->title}

gridsize is the name of my select field. And grid_settings is the name of my ConfigurationForm field (which contain multiple select fields). Item is the repeater item.

But this is not working. What Iam missing here?
Also is it possible to preselect an option?

Link to comment
Share on other sites

On 9/27/2018 at 2:22 PM, jploch said:

Also is it possible to preselect an option? 

Preselect option, currently, only in case when you have option value as null "0", as example your "gridsize" field:

Label: "Grid size"

-- option value: 0, option text: Default
-- option value: 1, option text: Grid size 1
-- option value: 2, option text: Grid size 2

In that case, preselected value in admin backend would be "Default".
Later in your code:

if ($item->grid_settings->gridsize){
// not default (not preselected value)
...
} else {
// default
...
}

But there is and "mix" variant, example, some select field with name background:

label: "Background color"

-- option value: 0, text: Default
-- option value: black, text: Black
-- option value: orange, text: Orange

* preselected text : "Default"

Later in code:

<?php
// configuration form field "settings" with select subfield "background"
$background = $page->settings->background ? '-' . $page->settings->background : '';
?>
<div class="bgn<?php echo $background;?>">

* div can have css class values: bgn, bgn-black, bgn-orange

Regards.

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Really like this module, using it to make a visual builder however I encountered that the uploading of files doesn't work. No errors is thrown.

It starts the ajax-upload but when it should be done it just disappear and the file isn't uploaded.

Currently debugging the issue. Will get back as soon as I find the issue.

But also wanted to see if anyone else encountered this?

Link to comment
Share on other sites

  • 4 months later...

@OLSA Hey man, I just found your amazing module while looking for an easy way to add a bunch of settings to a Profile Configuration page and I am trully impressed. I've seen some other great modules which I initially planned to use but to have a drag&drop functionality would make the development much easier for me (maybe I am too lazy).

I am testing it now and will see how will it work. At least I can combine the file upload/image uplad default PW fields with the "custom field" of your module and avoid the need of adding image paths etc.

Thank you for this masterpiece!

  • Like 1
Link to comment
Share on other sites

After a few quick tests, I found it pretty straight forward to echo the content of text/textarea.

In addition to the present functions of the module, it would be great if we could set the default state of the field (open, closed) as well as to have some logic of fields appearance based on other fields value (like it is with regular fields)

Link to comment
Share on other sites

  • 4 weeks later...
On 9/21/2018 at 9:32 PM, Macrura said:

if(wireCount($values)){

 

I had a similar issue, but in my scenario (with no module modifications) the line causing it was 58

if(count($values)){

I can confirm that changing the line to @Macrura correction eliminated the error in my logs.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...