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

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bernhard
      --- Please use RockFinder3 ---
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory (pending approval) If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By Craig
      I've been using Fathom Analytics for a while now and on a growing number of sites, so thought it was about time there was a PW module for it.
      WayFathomAnalytics
      WayFathomAnalytics is a group of modules which will allow you to view your Fathom Analytics dashboard in the PW admin panel and (optionally) automatically add and configure the tracking code on front-end pages.
      Links
      GitHub Readme & documentation Download Zip Modules directory Module settings screenshot What is Fathom Analytics?
      Fathom Analytics is a simple, privacy-focused website analytics tool for bloggers and businesses.

      Stop scrolling through pages of reports and collecting gobs of personal data about your visitors, both of which you probably don't need. Fathom is a simple and private website analytics platform that lets you focus on what's important: your business.
      Privacy focused Fast-loading dashboards, all data is on a single screen Easy to get what you need, no training required Unlimited email reports Private or public dashboard sharing Cookie notices not required (it doesn't use cookies or collect personal data) Displays: top content, top referrers, top goals and more
    • By daniels
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      You can find the Module in the Modules directory and on Github
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns *I have only tested it with PHP 7.x so far, so use on owners risk
      EDIT:
      Since 0.0.4, instructions and changelog can be found in the README only. You can find it here  🙂
      If you have questions or like to contribute, just post a reply or create an issue or pr on github, thanks!
    • By MoritzLost
      Sorry for the convoluted title. I have a problem with Process modules that define a custom page using the page key through getModuleInfo (as demonstrated in this excellent tutorial by @bernhard). Those pages are created automatically when the module is installed. The problem is that the title of the page only gets set in the current language. That's not a problem if the current language (language of the superuser who is installing the module) is the default language; if it isn't, the Process page is missing a title in the default language. This has the very awkward effect that a user using the backend in the default language (or any other language) will see an empty entry in the setup menu:

      This screenshot comes from my Cache Control module which includes a Process page. Now I realize the description sounds obscure, but for us it's a common setup: We a multiple bilingual sites where the default language is German and the second language is English. While the clients use the CMS in German, as a developer I prefer the English interface, so whenever I install a Process module I get this problem.
      As a module author, is there a way to handle this situation? I guess it would be possible to use post-installation hooks or create the pages manually, but I very much prefer the declarative approach. The page title is already translatable (through the __ function), but of course at the time of installation there is no translation, and as far as I'm aware it's not possible to ship translations with a module so they are used automatically. Could this situation be handled better in the core? I would prefer if the module installation process would always set the title of the Process page in the default language, instead of the language of the current user.
×
×
  • Create New...