Jump to content

single line for very long text in admin page list


pwfans
 Share

Recommended Posts

One of my clients site is using textarea field for main information, title field is not necessary to use, so when he use texarea in "List of fields to display in the admin Page List", page tree show multiple line with long text.

How to force textarea content to single line ?, just like gmail inbox : subject is auto truncate with menu show up at right side when hovering, it would be supernice if admin tree page list can be done like that.

Thanks

Link to comment
Share on other sites

I guess you could do a CSS solution: https://www.google.at/search?q=css+truncate+multiline+text&oq=css+truncate&aqs=chrome.1.69i57j0l5.4338j0j4&sourceid=chrome&ie=UTF-8

Or you could also create custom labels via a hook:

// /site/ready.php
$wire->addHookAfter('Pages::saveReady(template=yourtemplate)', function(HookEvent $event) {
  $page = $event->arguments(0);
  $page->yourcustomlabel = $this->sanitizer->truncate($page->yourtextarea, 150);
});

 

  • Like 2
Link to comment
Share on other sites

@bernhard

- CSS solution doesn't go, it will need this module which doesn't work on my side , i already read and do what docs said but css just not loading.

- Hook solution work !,  i'm blank with coding in hook, is there anyway to auto truncate by detecting template and field? no need to re save the page ? if it's need to work that way, it's ok, it's already much better than default, thanks a lot for this hook solution ?‍♂️

Link to comment
Share on other sites

4 hours ago, pwfans said:

Hook solution work !,  i'm blank with coding in hook, is there anyway to auto truncate by detecting template and field? no need to re save the page ? if it's need to work that way, it's ok, it's already much better than default, thanks a lot for this hook solution ?‍♂️

Don't know what you mean by auto truncate by template/field, but you have all information available in your hook:

// /site/ready.php
$wire->addHookAfter('Pages::saveReady', function(HookEvent $event) {
  $page = $event->arguments(0);
  $page->template; // yourtemplate
  $page->yourfield; // yourvalue

  if($page->template == 'foo') $page->bar = 'yournewvalue';
});

You need to save all existing pages. That's easy using TracyDebugger + Console:

$pages = $pages->find('yourselector');
$all = $pages->count();
foreach($pages as $i=>$p) {
  l("saving page $i/$all id $p");
  $p->save();
}

oq0Nz0L.png

If you have lots of pages you might run into execution timeouts and need to do that in batches (by appending ",sort=id,id>xxx" to your selector to skip already updated pages. Or you could only select non-updated pages via "yournewfield=" (empty) in your selector.

Link to comment
Share on other sites

For others need this solution using css, no need to use admin custom file module, just make custom admin css file inside template folder, add path to that css to admin.php inside template folder.

Original reference :

 

  • Like 1
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...