Jump to content
pwfans

single line for very long text in admin page list

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

Share this post


Link to post
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

Share this post


Link to post
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 🙇‍♂️

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thx for the reminder about admin.php - I'm always creating hooks for injecting custom scripts. admin.php might be easier and a better place 🙂 

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.

×
×
  • Create New...