Jump to content
Robin S

Template Field Widths

Recommended Posts

You were exactly right. It turned out to be the LoginRegister css putting the kabosh on me.

Again thanks for a great module, works perfectly.

  • Like 1

Share this post


Link to post
Share on other sites

First of all, thank you for this great module. Simplifies the whole process a lot.

Now please add Drag 'n' Drop of the fields and support for adding new fields to the template.

Also add field edit links to open the field editor in a popup/pane.

Switching between the field name and the field title would also be nice. And if you could display what fieldtype each field has.

And voilà we have a new and better template manager 🙂

Hey, I am allowed to have dreams.

  • Like 1

Share this post


Link to post
Share on other sites

You can use this to resize via mouse (using jQuery UI Resizable which seems to be present in the PW admin). I haven't checked fieldsets, I've updated the code, it's working fine with fieldsets too.

Spoiler

$(".tfw-item").resizable({
    containment: ".InputfieldContent",
    handles: "e",
    resize: function(event, ui) {
      var percentage = Math.ceil(ui.size.width / ui.element.parent().outerWidth() * 100);
      percentage = Math.min(Math.max(parseInt(percentage), 1), 100);
      ui.element.children("label").find("input").val(percentage);
      ui.element[0].style.width = percentage + "%";
    }
});

// CSS 

.tfw-item .ui-resizable-e {
    position: absolute;
    cursor: e-resize;
    width: 10px;
    right: 5px;
    top: 50%;
    height: 40px;
    transform: translateY(-50%);
    border-right: 1px solid #354b60;
    opacity: 0.5;
}

.tfw-item .ui-resizable-e:hover {
    opacity: 1;
}

.tfw-item .ui-resizable-handle.ui-resizable-e::after {
    content: "";
    position: absolute;
    top: 7px;
    right: 3px;
    height: 26px;
    width: 1px;
    background: #354b60;
}

.tfw-item:hover,
.tfw-item.ui-resizable-resizing {
    background: #e5ecf6;
}

.tfw-item {
    padding: 3px 14px 8px 10px;
    max-width: 100%;
    transition: none !important;
}

tfwresizable.thumb.gif.2c4bc8577cc146b037f559db6f905a5c.gif

  • Like 7

Share this post


Link to post
Share on other sites
12 hours ago, jmartsch said:

Switching between the field name and the field title would also be nice.

v0.1.6 has a new config option to choose Name or Label as the primary identifier for fields. Whichever isn't chosen becomes the title attribute shown on hover.

Thanks @tpr - in v0.1.6 I added your drag resizing code mostly unchanged. It's not something I think I'll use myself but very cool nonetheless.

  • Like 4

Share this post


Link to post
Share on other sites

Thanks Robin - have you checked the drag resize with tabs? I didn't have time to check that scenario.

Share this post


Link to post
Share on other sites
1 minute ago, tpr said:

have you checked the drag resize with tabs?

You mean fields inside a FieldsetTab? If so then yes, it works well.

Share this post


Link to post
Share on other sites

Yes, I just checked and I see that they are also under a tab (I thought it's configurable).

Share this post


Link to post
Share on other sites

Perhaps a minor bug: if I select "Label" as the primary identifier then no text is shown for the field. Imho the module should display the primary identifier, and if not available, the name (as that's always available).

Plus it would be better to put the "title" tag on the main div (.tfw-item) so it would be always available. This introduces another issue: hovering on an input the tooltip still shows but you can disable it by adding an empty title tag to the input (at least it works for Chrome).

  • Like 1

Share this post


Link to post
Share on other sites
32 minutes ago, tpr said:

Perhaps a minor bug: if I select "Label" as the primary identifier then no text is shown for the field. Imho the module should display the primary identifier, and if not available, the name (as that's always available).

Thanks, I always forget about this possibility because in my default site profile I automatically derive field labels from names.

Spoiler

$this->addHookBefore('ProcessField::executeSave', $this, 'autoFieldLabel');

/**
 * Derive field label from field name
 *
 * @param HookEvent $event
 */
protected function autoFieldLabel(HookEvent $event) {
	$post = $this->wire()->input->post;
	// Only for "Add New Field" and only if label is empty
	if(!$this->wire()->input->get->id && !$post->field_label) {
		$post->field_label = ucfirst(str_replace('_', ' ', $post->name));
	}
	// Add hook if field is being cloned
	if($post->clone_field) {
		$this->wire()->addHookBefore('Fields::save', $this, 'autoCloneFieldLabel');
	}
}

/**
 * Derive field label from field name after clone
 *
 * @param HookEvent $event
 */
protected function autoCloneFieldLabel(HookEvent $event) {
	$field = $event->arguments(0);
	if($field->name === $this->wire()->input->post->clone_field) {
		$field->label = ucfirst(str_replace('_', ' ', $field->name));
	}
}

 

Fixed in v0.1.7.

 

40 minutes ago, tpr said:

Plus it would be better to put the "title" tag on the main div (.tfw-item) so it would be always available.

It's actually deliberate the way it is. Title tooltips can be a distracting irritant when you don't have an intention to see them. I wanted there to be some intentionality required for them to appear, so you need to hover the field identifier (which is block level so it's pretty easy to mouse to) rather than having tooltips popping up whenever your mouse is anywhere inside "Field widths".

Share this post


Link to post
Share on other sites

Thanks for the fix.

Actually the block level field identifier was what made me think that the tooltip was intended to be triggered on the whole block. As it is now on the far right side there is no indication where the tooltip will be triggered when you move the mouse. Perhaps it would be better to restrict it to the identifer text only, or prepending an info icon. Anyway, no biggie.

I created a PR to disallow less then 10% field widths, because PW doesn't allow that:

Quote

The percentage width of this field's container (10%-100%). If placed next to other fields with reduced widths, it will create floated columns.

TFWs allowed setting lower percentages and those values were kept. However, such fields were defaulting to 100%, just like the field's width sliders on the edit field page.

  • Like 2

Share this post


Link to post
Share on other sites
40 minutes ago, tpr said:

Perhaps it would be better to restrict it to the identifer text only, or prepending an info icon.

I think I'll leave it for now unless I hear from others who are finding it confusing.

41 minutes ago, tpr said:

I created a PR to disallow less then 10% field widths, because PW doesn't allow that

I didn't know PW had that restriction. Thanks, have merged in v0.1.8.

  • Like 1

Share this post


Link to post
Share on other sites

When I try to edit a template that gets its fields from another template, I get an error:

Argument 2 passed to ProcessWire\InputfieldWrapper::insertAfter() must be an instance of ProcessWire\Inputfield, null given, called in C:\inetpub\wwwroot\site\modules\TemplateFieldWidths\TemplateFieldWidths.module on line 152

Possible fix:

if($fg_fields) $form->insertAfter($f, $fg_fields);

 

  • Like 1

Share this post


Link to post
Share on other sites

v0.1.10 released.

Now that new core ways of setting field widths in template context have been introduced it seems that users are sometimes setting a field width using a core input and then saving the Edit Template form. Although it's not necessary to save the Edit Template form after adjusting a field width using a core input (those settings are AJAX-saved), it's not unlikely that users will do this and in these circumstances the old width stored in the Template Field Widths inputfield was overwriting the new width.

So from v0.1.10 onward the widths entered into the Template Field Widths inputfield are only saved if Edit Template is saved with the Template Field Widths inputfield in a open state. And it's recommended to use the default "Collapsed" config option for Template Field Widths if you think you might also use core inputs for setting field widths.

2019-10-15_093852.png.9c6d3128a1705bcd66110a36667f9721.png

  • Like 2

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 Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful, developer-first 3rd party HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development:
      2020-01-19 --> integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 --> new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 --> orders filter, order details, download + resend invoices, refunds 2019-10-18 --> list filters, REST API improvements, new docs platform, and more ... 2019-08-08 --> dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 --> taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 --> FieldtypeSnipWireTaxSelector 2019-05-25 --> SnipWire will be free and open source If you are interested, you can test the current state of development:
      https://github.com/gadgetto/SnipWire
      If you like, you can also submit feature requests and suggestions for improvement. I also accept pull requests.
      ---- INITIAL POST FROM 2019-05-25 ----
      I wanted to let you know that I am currently working on a new ProcessWire module that fully integrates the Snipcart Shopping Cart System into ProcessWire. (this is a customer project, so I had to postpone the development of my other module GroupMailer).
      The new module SnipWire offers full integration of the Snipcart Shopping Cart System into ProcessWire.
      Here are some highlights:
      simple setup with (optional) pre-installed templates, product fields, sample products (quasi a complete shop system to get started immediately) store dashboard with all data from the snipcart system (no change to the snipcart dashboard itself required) Integrated REST API for controlling and querying snipcart data webhooks to trigger events from Snipcart (new order, new customer, etc.) multi currency support self-defined/configurable tax rates etc. Development is already well advanced and I plan to release the module in the next 2-3 months.
      I'm not sure yet if this will be a "Pro" module or if it will be made available for free.
      I would be grateful for suggestions and hints!
      Please have a look at the screenshots to get an idea what I'm talking about (open spoiler):
      (Please note: these screenshots are from an early development state of SnipWire. To see actual screens please have a look at later posts below!)
       
    • By MateThemes
      Hello everyone!
      I have a markup and image field question:
      I have a markup in which a gallery preview should be displayed on home page. This gallery have a special markup, 3 of 4 images have special image ratio.

      The gallery looks like this. 
      The html markup is like this:
      <div class="uk-section-muted" uk-scrollspy="target: [uk-scrollspy-class]; cls: uk-animation-slide-top-small; delay: 200;"> <div data-src="./assets/images/arrahof/home-restaurant-bg.svg" class="uk-background-norepeat uk-background-contain uk-background-top-center uk-section uk-section-large" uk-img> <div class="uk-container uk-container-small"> <div class="uk-margin-large" uk-grid> <div class="uk-width-1-1@m"> <h2 class="uk-text-center" uk-scrollspy-class>Das Angebot im ArraHof</h2> </div> </div> <div class="uk-grid-small uk-grid-margin-small" uk-grid> <div class="uk-width-expand@s"> <div class="uk-margin-remove-vertical uk-text-center" uk-scrollspy-class> <a class="el-container uk-inline-clip uk-transition-toggle uk-link-reset" href="#"> <img class="el-image" data-src="https://via.placeholder.com/610x604" data-sizes="(min-width: 610px) 610px" data-width="610" data-height="604" alt="Placeholder Image" uk-img> <div class="uk-overlay-default uk-transition-fade uk-position-cover"></div> <div class="uk-position-center uk-position-small"> <div class="uk-overlay uk-padding-large uk-transition-fade uk-margin-remove-first-child"> <h3 class="el-title uk-h4 uk-heading-divider uk-transition-slide-top-small uk-margin-top uk-margin-remove-bottom">Lorem Ipsum</h3> <div class="el-content uk-panel uk-transition-slide-bottom-small uk-margin-top">Comfort Food</div> </div> </div> </a> </div> </div> <div class="uk-width-expand@s"> <div class="uk-margin-remove-vertical uk-text-center" uk-scrollspy-class> <a class="el-container uk-inline-clip uk-transition-toggle uk-link-reset" href="#"> <img class="el-image" data-src="https://via.placeholder.com/610x604" data-sizes="(min-width: 610px) 610px" data-width="610" data-height="604" alt="Placeholder Image" uk-img> <div class="uk-overlay-default uk-transition-fade uk-position-cover"></div> <div class="uk-position-center uk-position-small"> <div class="uk-overlay uk-transition-fade uk-margin-remove-first-child"> <h3 class="el-title uk-h4 uk-heading-divider uk-transition-slide-top-small uk-margin-top uk-margin-remove-bottom">The Williams family</h3> <div class="el-content uk-panel uk-transition-slide-bottom-small uk-margin-top">Comfort Food</div> </div> </div> </a> </div> </div> </div> <div class="uk-grid-small uk-grid-margin-small" uk-grid uk-height-match="target: .uk-card; row: false"> <div class="uk-width-2-3@s"> <div class="uk-margin-remove-vertical uk-text-center" uk-scrollspy-class> <a class="el-container uk-inline-clip uk-transition-toggle uk-link-reset" href="#"> <img class="el-image" data-src="https://via.placeholder.com/610x400" data-width="610" data-height="400" alt="Placeholder Image" uk-img> <div class="uk-overlay-default uk-transition-fade uk-position-cover"></div> <div class="uk-position-center uk-position-small"> <div class="uk-overlay uk-transition-fade uk-margin-remove-first-child"> <h3 class="el-title uk-h4 uk-heading-divider uk-transition-slide-top-small uk-margin-top uk-margin-remove-bottom">The Williams family</h3> <div class="el-content uk-panel uk-transition-slide-bottom-small uk-margin-top">Comfort Food</div> </div> </div> </div> </a> </div> <div class="uk-width-expand@s"> <div class="uk-margin-remove-vertical uk-text-center" uk-scrollspy-class> <a class="el-container uk-inline-clip uk-transition-toggle uk-link-reset" href="#"> <img class="el-image" data-src="https://via.placeholder.com/610x820" data-sizes="(min-width: 610px) 610px" data-width="610" data-height="820" alt="Placeholder Image" uk-img> <div class="uk-overlay-default uk-transition-fade uk-position-cover"></div> <div class="uk-position-center uk-position-small"> <div class="uk-overlay uk-transition-fade uk-margin-remove-first-child"> <h3 class="el-title uk-h4 uk-heading-divider uk-transition-slide-top-small uk-margin-top uk-margin-remove-bottom">The Williams family</h3> <div class="el-content uk-panel uk-transition-slide-bottom-small uk-margin-top">Comfort Food</div> </div> </div> </div> </a> </div> </div> </div> <div class="uk-margin-large" uk-grid> <div class="uk-width-1-1@m"> <div class="uk-text-lead uk-width-xxlarge uk-margin-auto uk-text-center" uk-scrollspy-class>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur.</div> <div class="uk-margin-medium uk-text-center" uk-scrollspy-class> <a class="el-content uk-button uk-button-default uk-button-large" href="#">Unterkunft</a> </div> </div> </div> </div> </div> How can I achieve when I have an image field to add the custom markup within the image field? I have no clue to get this done.
      Thank you!
    • By d'Hinnisdaël
      Happy new year, everybody 🥬
      I've been sitting on this Dashboard module I made for a client and finally came around to cleaning it up and releasing it to the wider public. This is how it looks.
      ProcessWire Dashboard

      If anyone is interested in trying this out, please go ahead! I'd love to get some feedback on it. If this proves useful and survives some real-world testing, I'll add this to the module directory.
      Download
      You can find the latest release on Github.
      Documentation
      Check out the documentation to get started. This is where you'll find information about included panel types and configuration options.
      Custom Panels
      My goal was to make it really simple to create custom panels. The easiest way to do that is to use the panel type template and have it render a file in your templates folder. This might be enough for 80% of all use cases. For anything more complex (FormBuilder submissions? Comments? Live chat?), you can add new panel types by creating modules that extend the DashboardPanel base class. Check out the documentation on custom panels or take a look at the HelloWorld panel to get started. I'm happy to merge any user-created modules into the main repo if they might be useful to more than a few people.
       Disclaimer
      This is a pre-release version. Please treat it as such — don't install it on production sites. Just making sure 🍇
      Roadmap
      These are the things I'm looking to implement myself at some point. The wishlist is a lot longer, but those are the 80/20 items that I probably won't regret spending time on.
      Improve documentation & add examples ⚙️ Panel types Google Analytics ⚙️ Add new page  🔥 Drafts 🔥 At a glance / Page counter 404s  Layout options Render multiple tabs per panel panel groups with heading and spacing between ✅ panel wrappers as grid item (e.g. stacked notices) ✅ Admin themes support AdminThemeReno and AdminThemeDefault ✅ Shortcuts panel add a table layout with icon, title & summary ✅ Chart panel add default styles for common chart types ✅ load chart data from JS file (currently passed as PHP array) Collection panel support image columns ✅ add buttons: view all & add new ✅
    • By Robin S
      This module is inspired by and similar to the Template Stubs module. The author of that module has not been active in the PW community for several years now and parts of the code for that module didn't make sense to me, so I decided to create my own module. Auto Template Stubs has only been tested with PhpStorm because that is the IDE that I use.
      Auto Template Stubs
      Automatically creates stub files for templates when fields or fieldgroups are saved.
      Stub files are useful if you are using an IDE (e.g. PhpStorm) that provides code assistance - the stub files let the IDE know what fields exist in each template and what data type each field returns. Depending on your IDE's features you get benefits such as code completion for field names as you type, type inference, inspection, documentation, etc.
      Installation
      Install the Auto Template Stubs module.
      Configuration
      You can change the class name prefix setting in the module config if you like. It's good to use a class name prefix because it reduces the chance that the class name will clash with an existing class name.
      The directory path used to store the stub files is configurable.
      There is a checkbox to manually trigger the regeneration of all stub files if needed.
      Usage
      Add a line near the top of each of your template files to tell your IDE what stub class name to associate with the $page variable within the template file. For example, with the default class name prefix you would add the following line at the top of the home.php template file:
      /** @var tpl_home $page */ Now enjoy code completion, etc, in your IDE.

      Adding data types for non-core Fieldtype modules
      The module includes the data types returned by all the core Fieldtype modules. If you want to add data types returned by one or more non-core Fieldtype modules then you can hook the AutoTemplateStubs::getReturnTypes() method. For example, in /site/ready.php:
      // Add data types for some non-core Fieldtype modules $wire->addHookAfter('AutoTemplateStubs::getReturnTypes', function(HookEvent $event) { $extra_types = [ 'FieldtypeDecimal' => 'string', 'FieldtypeLeafletMapMarker' => 'LeafletMapMarker', 'FieldtypeRepeaterMatrix' => 'RepeaterMatrixPageArray', 'FieldtypeTable' => 'TableRows', ]; $event->return = $event->return + $extra_types; }); Credits
      Inspired by and much credit to the Template Stubs module by mindplay.dk.
       
      https://github.com/Toutouwai/AutoTemplateStubs
      https://modules.processwire.com/modules/auto-template-stubs/
×
×
  • Create New...