diff --git a/src/templates/_input.html b/src/templates/_input.html index d880478..e530b79 100644 --- a/src/templates/_input.html +++ b/src/templates/_input.html @@ -1,22 +1,93 @@ {% import '_includes/forms' as forms %} {% if field.allowMultiple %} - {{ forms.checkboxGroup({ - id : field.handle, - name : field.handle, - values: value, - placeholder: 'Choose Sites...' | t('sites-field'), - options: sites - }) }} +
+ +
+ {% set siteIds = siteIds ?? craft.app.sites.getEditableSiteIds() %} + {% if siteIds|length %} + {% if selectedSiteId is not defined %} + {% if craft.app.sites.currentSite.id in siteIds %} + {% set selectedSiteId = craft.app.sites.currentSite.id %} + {% else %} + {% set selectedSiteId = siteIds|first %} + {% endif %} + {% endif %} + {% set groups = craft.app.sites.getAllGroups() %} + + {% for group in groups %} + {% set groupSiteIds = group.getSiteIds()|intersect(siteIds) %} + {% if groupSiteIds %} + {% if groups|length > 1 %}
{{ group.name|t('site') }}
{% endif %} + + {% endif %} + {% endfor %} + {% endif %} +
+
{% else %} - {{ forms.select({ - id : field.handle, - name : field.handle, - value: value, - placeholder: 'Choose a Site...' | t('sites-field'), - options: sites - }) }} - {% if value is iterable %} -

{{ "Multiple sites selected, but field only allows one site. Selecting a new value will clear the existing multiple sites selection." | t('sites-field') }}

- {% endif %} +
+ +
+{% if value is iterable %} +

{{ "Multiple sites selected, but field only allows one site. Selecting a new + value will clear the existing multiple sites selection." | t('sites-field') }}

+{% endif %} {% endif %}