sjelfull / craft3-templateselect

A fieldtype that allows you to select a template from the site templates folder.
https://superbig.co
MIT License
17 stars 9 forks source link

FR: Use autosuggest component for template selection #13

Open tomkiss opened 1 year ago

tomkiss commented 1 year ago

This fork changes the plugins form element to use the autosuggest component, which improves template selection through the improved UI.

sjelfull commented 6 months ago

@tomkiss Thanks for this PR! I didn't actually notice it until I did a major change where I added support for "beautifying" the paths and file names in the template select input.

Do you know if the autosuggest field has a way to control the rendering of the value?

tomkiss commented 6 months ago

Hi @sjelfull,

You can't really style as such, but you can provide a "hint" that will render in the field.

For example, when rendering a field normally, you can send it something like this:

  'data' => ['Domestic Cat', 'Leopard', 'Lion']

But, you could use the hint property to improve what's displayed. Like so:

  'data' => [
      [
          'name' => 'Domestic Cat',
          'hint' => 'Your friend at home',
      ],
      [
          'name' => 'Leopard',
          'hint' => 'Classic Apple operating system',
      ],
      [
          'name' => 'Lion',
          'hint' => 'MGM',
      ]
  ]

...which would result in a UI that renders something like this:

Screenshot 2024-05-13 at 13 41 15

So, you could lead with the template name, then hint the full path?