isellsoap

Show field label besides field name in "edit template" view. Possible?

Recommended Posts

isellsoap    84

See screenshot for a better understanding of my question:

post-1086-0-87176800-1375453255_thumb.jp

I have lots of generic field names per template (the generic naming is for scalability/simplicity reasons and necessary), so it would be nice to have the field label show up besides the field name for better overview. Is this possible? The status quo is ok-ish, but the field label showing up would be neat, faster and save me some clicks.

  • Like 1

Share this post


Link to post
Share on other sites
diogo    4,507

Go the template "advanced" tab, and add the fields you want to the "List of fields to display in the admin Page List" input

Share this post


Link to post
Share on other sites
kongondo    5,003

Go the template "advanced" tab, and add the fields you want to the "List of fields to display in the admin Page List" input

Diogo,

Am not sure that's what he's after? The screenshot is of the Tempate->Basics screen where you can add fields to the template. He wants those rows/list of fields (the asmList), in addition to the field name, to show the field label. What you are suggesting is for the Page Tree, no?

Share this post


Link to post
Share on other sites
ryan    13,367

Currently you can't show field labels rather than names in the template editor. This part is meant to be for the developer, who would typically know fields by their names rather than labels. Like in your template files, you'd refer to fields here by their names. Field labels are more for clients, language translation, etc.



I would suggest using more descriptive names than float_field_1, float_field_2, etc., because there's no way to tell what that is, outside of the label. It could make the code in your site's template files difficult to maintain and navigate. 

Share this post


Link to post
Share on other sites
isellsoap    84

Thanks for the comments.

@ryan: like I wrote in the first post, the generic names are necessary because of scalability reasons in the long run. The fields represent single entries of companies’ quarterly results. Because of the heterogenity of those results (every company has slightly different naming conventions for their financial stuff), it wouldn’t be very wise to create 30 to 50 fields per company (that would result in 30,000 to 50,000 fields for 1,000 companies). Instead, I have 50 generic field names for 1,000 companies.

I think also that it is definitely a bit difficult to navigate through template files (in my case the fields are used in a module) and check, which field represents what for a single company, but I think it’s far better than having thousands and thousand of fields in total.

Share this post


Link to post
Share on other sites
kongondo    5,003

I think also that it is definitely a bit difficult to navigate through template files (in my case the fields are used in a module) and check, which field represents what for a single company, but I think it’s far better than having thousands and thousand of fields in total.

I can think of different ways to deal with this one. 

  1. Printout: As someone suggested in the forums (Maybe Renobird?), they print out a list of all the fields on their site and what the fields are for.
  2. Admin page: Maybe create a hidden page, under Admin, with a list of all the fields and what they represent for each company?
  3. Custom Admin page: Create a custom admin page using Diogo's Admin Custom Page module that renders only for superuser showing you the list of fields and what they represent for each company. Maybe this is best because you can view it as read only and can get as creative as you want with the output

Just thinking out loud here...

  • Like 3

Share this post


Link to post
Share on other sites
isellsoap    84

Super cool ideas, thanks a lot! Point #3 sounds really good.

The more I learn about ProcessWire and use it, the more I love it. ^_^

  • Like 2

Share this post


Link to post
Share on other sites
ryan    13,367
@ryan: like I wrote in the first post, the generic names are necessary because of scalability reasons in the long run. The fields represent single entries of companies’ quarterly results. Because of the heterogenity of those results (every company has slightly different naming conventions for their financial stuff), it wouldn’t be very wise to create 30 to 50 fields per company (that would result in 30,000 to 50,000 fields for 1,000 companies). Instead, I have 50 generic field names for 1,000 companies.

Sounds like you have pretty unique needs here, and I understand now – your approach does make sense given the context. I think Kongondo's ideas are good here, and I will keep thinking about how we might support separate labels in the asmSelect list there for the future. 

  • Like 1

Share this post


Link to post
Share on other sites
muzzer    86

Similar (related) question. I have templates with up to 50 fields. I don't work in the Admin much but do use it to lookup values on pages and with my poor memory, and even with pretty good naming convention for my fields (some are similar) I often lose track of field names. Is there any way (short of manually appending the field name to the label) to show both label and field name above the field input. Essentially, is there somewhere an option to automatically append the field name to the field label. Please see screenshot for basic idea:

Thx

2017-04-25 14_29_03-Edit Page.png

Share this post


Link to post
Share on other sites
tpr    2,212

Use AdminOnSteroids and enable Field and Template edit links, then hover on field label to see field name in a tooltip, or edit on click.

  • Like 4

Share this post


Link to post
Share on other sites
abdus    550

You can do this with a few lines of JS

(function(){
    let inputs = document.querySelectorAll('.InputfieldWrapper .Inputfield');

    [].forEach.call(inputs, item => {

        let input = item.querySelector('[name]');
        if(!input) return;

        let label = item.querySelector('label');
        if(!label) return;

        let inputName = label.htmlFor.replace(/(\w+)_(\w+)/, '$2');


        let span = document.createElement('span');
        span.style.display = 'inline-block';
        span.style.color = 'tomato';
        span.style.border = '2px solid';
        span.padding = '0.25em 0.25em';
        span.margin = '0 0 0 0.25em'

        span.innerHTML = inputName;
        label.appendChild(span);

    });
})();

Run this in Developer Console on your browser and you'll get this

chrome_2017-04-25_08-22-24.png.b4462b95f20a5eafcc3be826ce2eff8d.png

To automate this, you can put this script in a JS file in /site/templates/admin/labels.js, and enqueue it inside your /site/ready.php

// /site/ready.php

if ($page->template->name === 'admin') {
    $config->scripts->add($config->urls->templates . 'admin/label.js');
}

 

  • Like 5

Share this post


Link to post
Share on other sites
szabesz    1,377

I do not have the time to present an exact solution, but I think it is worth to mention that @Robin S came up with something similar using Hanna Codes (it uses the description field for such purposes, but should work in any admin themes):

 

  • Like 2

Share this post


Link to post
Share on other sites
muzzer    86

Hey @abdus, Thank you! I was not aware you could do anything like this! Love it.
BTW the ugly styling in my screenshot was just the default from the snipping app, I never meant you to copy it so accurately! Bonus points for that.

@tpr thanks for the AdminOnSteriods suggestion, it looks interesting, will check it out. Cool name too.

Share this post


Link to post
Share on other sites
Robin S    2,487

One more option: when debug mode is true you can hover the inputfield open/close toggle to see the field name.

2017-05-05_164623.png.97e9bdc71ccd2c7ad2e64c404bce1b7f.png

  • Like 1

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 valan
      I've spent few hours at this problem, but still can't solve it -
      // this code works not as expected - outputs only in default language, even if $user->language is different. echo $user->fields->get("some_text_field")->label; // while this code in the same php file works as expected - output follows $user->language echo $page->any_field;  Note: some_text_field field label is a multi-language field, all translations available.
      If I try to do something like this:
      echo $user->fields->get("some_text_field")->label->getLanguageValue($user->language); it returns:
      Please, help - I want to output field label in current language! )) Thanks!