Jump to content

New post – FieldsetGroup module released


ryan
 Share

Recommended Posts

Hey @ryan, thanks for the update as always.

I may have found a bug. Or it might be specific to my system too. I'm not sure. When I create a FieldsetGroup, I can't edit it, and I get this error: (I'm on v3.0.74)

59b2f9d3c9790_2017-09-0823_12_02-Error_CalltoamemberfunctionaddClass()onnull.png.bfbc20e9c84ef6753c9b42a19504ea23.png

Putting a breakpoint inside the method, I see:

$this->wire('modules')->get('InputfieldFieldsetOpen')

returns null.

I've searched the core for that module. It appears inside FieldtypeFieldsetOpen.module like this:

class InputfieldFieldsetOpen extends InputfieldWrapper { } // empty definition
class FieldtypeFieldsetOpen extends Fieldtype { /* ... */ }

When I try to get the module manually using $modules->InputfieldFieldsetOpen, it doesnt work either. I tried refreshing module cache, but it didnt help.

Then I refactored InputfieldFieldsetOpen into its own module file under /wire/modules/Inputfields/InputfieldFieldsetOpen.module (without removing it from FieldtypeFieldsetOpen.module), and refreshed module cache (and remove the definition from FieldtypeFieldsetOpen.module), PW recognizes the module and I can edit the field now.

  • Like 1
Link to comment
Share on other sites

Also, while adding fields to the fieldset, unless I am missing something, the field's _END counterpart shouldn't show up:

59b2fe6cbb6c6_2017-09-0823_31_53-EditField_pageContentabdus_dev.thumb.png.6f70d8349d2ba3f2705bce18a2c527f7.png

Inside FieldgroupConfig.php, I tried removing closing field, but the solution I found isn't really pretty. 

$f instanceof FieldtypeFieldsetClose

always return false for all FieldsetClose (fieldset, tabs, fieldsetfieldgroups etc) fields

 

public function getConfigInputfields(Field $field, InputfieldWrapper $inputfields)
{
    // ...

    foreach ($this->wire('fields') as $f) {
        if ($f->id == $field->id) continue;
        if ($template && $template->fieldgroup->has($f)) continue;
        if ($f->name == $field->name) continue;
        // WORKING skip its own closing field
        if ($f->name === "{$field->name}_END") continue;
        // NOT WORKING 
        // $f instanceof FieldtypeFieldsetClose is never true for _END fields
        if($f instanceof FieldtypeFieldsetClose && strpos($f->name, $field->name) === 0) continue;
        
        // ...
        $select->addOption($f->id, $name, $attrs);
    }

    // ...
}

 

  • Like 1
Link to comment
Share on other sites

Thank you Ryan!

Both modules look awesome! And I see use cases for both of them on sites I am working on right now. It is especially nice to see these developed in response to a community feedback made through a PW weekly poll. And this is the first reason I hope both fill be released in the core. The second is that that FieldsetGroup is such a natural and kind of even expected extension of the regular fieldset it must be valuable to many. I got my ProFields subscription anyways, but still... :rolleyes:

  • Like 1
Link to comment
Share on other sites

First of all thank you @ryan.

This is why I love ProcessWire: The community requests a feature and instead of just realizing it, you come up with multiple solutions to this request. :)

I have tried the new FieldsetGroup and it comes in really handy. I had only two issues:

  1. The bug @abdus mentioned earlier in line 475. I have commented it out in the module for now, to get the module working, but hopefully it wasn't anything necessary and will be fixed.
  2. Is it correct, that the fields inside the FieldsetGroup only get added to the template, if you use the actions tab inside the field configuration? I tried adding it in the template configuration, but it only added the fieldset, not the fields inside the fieldset. Maybe it is a bug, but I would have expected it to add all the fields.

Regards, Andreas

  • Like 3
Link to comment
Share on other sites

Quote

I may have found a bug. Or it might be specific to my system too. I'm not sure. When I create a FieldsetGroup, I can't edit it, and I get this error: (I'm on v3.0.74)

I can't duplicate that one here yet, but InputfieldFieldsetOpen is a quasi module, so starting to see how that might happen. Wondering if you change line 472 to this, if that fixes it?  

$inputfield = parent::getInputfield($page, $field);
Quote

Also, while adding fields to the fieldset, unless I am missing something, the field's _END counterpart shouldn't show up:

You are right there's no reason for it to show that, so I'll update to exclude it. The working solution you found is the way I usually do it. However, you could also do if($f->type instanceof FieldtypeFieldsetClose).  

Quote

Is it correct, that the fields inside the FieldsetGroup only get added to the template, if you use the actions tab inside the field configuration? I tried adding it in the template configuration, but it only added the fieldset, not the fields inside the fieldset. Maybe it is a bug, but I would have expected it to add all the fields.

It will add the fields, but you have to hit "Save" first. So add the FieldsetGroup field to your template, then Save, and then you'll see the fields in the fieldset. 

 

  • Like 2
Link to comment
Share on other sites

Thank you for the fix. :)

1 hour ago, ryan said:

It will add the fields, but you have to hit "Save" first. So add the FieldsetGroup field to your template, then Save, and then you'll see the fields in the fieldset.

I tried to add the FieldsetGroup to my template inside the template configuration and saved, but it only adds the outer fields of the FieldsetGroup without the fields inside.

Strange thing is, that when I deleted the FieldsetGroup from the template, the messages show that the missing fields inside the FieldsetGroup have been deleted as well.

Here is a little screencast, to show what I mean:

FieldsetGroup.thumb.gif.8450d31c2533d94a4532d3a6826d90ba.gif

Link to comment
Share on other sites

It might be that you have to grab the current dev branch. I probably should have bumped the version up to 3.0.75, but was thinking there weren't enough differences. I must be wrong about that. If you grab a fresh copy of 3.0.74, chances are it should work. 

Link to comment
Share on other sites

Sorry for bothering you again, but after I have grabbed the latest dev branch (with the five commits after the latest bump to version 3.0.74), I still have this behavior. It is not a real issue for me right now and if you want, I can create a new thread in the ProFields section. Just wanted to let you know. Keep up the great work. ;)

Link to comment
Share on other sites

@AndZyk Just to confirm, this is your process adding the field:

1. Go to Setup > Templates > some-template

2. Add the FieldsetGroup field (example name: test_fieldset). It should automatically add the test_fieldset_END field, so that you see test_fieldset followed by test_fieldset_END

3. Save the template.

4. When the page reloads, you should see test_fieldset, followed by all the fields in the fieldset, then test_fieldset_END

From what I gather (and from your GIF earlier), on step 4, you don't see the fields in the fieldset, and instead see just test_fieldset and test_fieldset_END - is this correct? If so, are you doing anything else between steps 2 and 3, like sorting of fields or changing other settings before saving? If so, I'd need to know what so I can attempt to reproduce here.

The way it adds the fields to the fieldset is in the hookTemplateFieldAdded method on line 657 of FieldtypeFieldsetGroup.module. That hook is called after a field is added from ProcessTemplate.module. I can step through and watch it get called from here, so am thinking perhaps the hook isn't getting called in your case for some reason.

The only other thing I can identify is that it looks like you are running a custom admin theme. It might be worth trying with the default admin theme, just in case. Though I kind of doubt that's it. It might also be worth testing on a clean installation, just in case there is some other module or hook at play that is specific to this installation. 

Link to comment
Share on other sites

I have tested it now with an clean installation and there it works like expected. That doesn't explain why it is not working for me, but at least it is not a bug. :lol:

It seems to be something else interfering, I have to look a little bit.

Edit: Okey I am absolutely clueless. I tried removing all modules and creating a new template and fieldset. I give up for now. ;)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...