Jump to content

Add class to InputfieldWrapper (editing a module)


a-ok
 Share

Recommended Posts

I'm needing to add a class `uk-grid-margin` to a `ul.Inputfields` in the admin for @adrian's TableCsvImportExport module https://github.com/adrianbj/TableCsvImportExport/blob/master/TableCsvImportExport.module.php

I thought adding `$fieldset->addClass('foobar', 'Inputfields');` would work but it doesn't. I've tried adding this directly to the `$inputfields = new InputfieldWrapper();` also.

Any thought if this is possible? See screenshots as a helper.

 

Screenshot 2020-04-09 at 11.24.01.jpg

Screenshot 2020-04-09 at 11.27.33.jpg

Link to comment
Share on other sites

I've no experience with this module, but you can modify all markup inside the <div class="InputfieldContent"> via the Inputfield's render method:

$wire->addHookAfter("Inputfield::render", function($event) {
  $event->return = "<div>foo</div>".$event->return;
});

If that does not work for your case it might be due to this issue: https://github.com/processwire/processwire-issues/issues/1141 (if that is also an issue for you it would be great to add your problem description there so that ryan sees that it is not only my problem ? )

Link to comment
Share on other sites

@a-ok - this stuff has always frustrated me - it seems like it's only possible to add classed to an InputfieldWrapper when it's added to a form (which I do in the AdminActions module). I can't get the same code to work for this module. How about I add this:

        $inputfields = new InputfieldWrapper();

        $margin = $this->wire('modules')->get("InputfieldMarkup");
        $margin->value = '<div class="uk-margin-small-top"></div>';
        $inputfields->add($margin);

as a hack to get some space between the Add Row button and the Import/Export CSV section?

  • Like 1
Link to comment
Share on other sites

@adrian I really appreciate a reply from the main man himself.

Your solution sounds good given the situation.

I ended up adding a margin top to both the fieldsets in the end, which maybe breaks some of the visual style of the expanded fields, and added margin bottom to the import/export buttons. I also changed the first row names to labels for the export.

This is silly stuff; the main thing is the module, which works great and really thankful for the contribution. So thanks! ????

Link to comment
Share on other sites

I suppose the names/labels option should be configurable.

I am low on time at the moment - any chance you feel like putting tother a PR to add that and throw in that new top margin hack as well?

 

Link to comment
Share on other sites

Aiming to do this this weekend.

I had another question. Is it possible to configure whether the inputfields for Import and Export are added to the bottom or the top of the PageTable? It currently does this:

$inputfields->add($fieldset);
return $event->return .= $inputfields->render();

Which simply concats it to the end, but I wonder if there's an alternative? If the PageTable gets long having to scroll to bottom for the Import/Export isn't fun so maybe a configurable option?

  • Like 1
Link to comment
Share on other sites

On 4/11/2020 at 2:21 PM, adrian said:

@a-ok - I am happy if you want to include a config setting that allows them to be added to the top.

I'm struggling working out how to set the Import/Export fieldsets to the top.

Anyone got any idea? 

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...