From 2ba4657ad4ba8630319b6ce126ddf0b3d4be0778 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 10 Feb 2026 21:36:15 +0000
Subject: [PATCH] =autocomplete data attribute added

---
 inc/meta/Form.php |  120 +++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 75 insertions(+), 45 deletions(-)

diff --git a/inc/meta/Form.php b/inc/meta/Form.php
index e2b4a45..b20fc27 100644
--- a/inc/meta/Form.php
+++ b/inc/meta/Form.php
@@ -87,7 +87,7 @@
 	// Helper Methods
 	// ─────────────────────────────────────────────────────────────
 
-	protected static function fieldWrap(string $name, string $content, array $config): string
+	public static function fieldWrap(string $name, string $content, array $config): string
 	{
 		$classes = static::buildClasses($config);
 		$datasets = static::buildDatasets($config);
@@ -103,13 +103,15 @@
 			$datasets
 		);
 
+		$output .= static::buildCharacterLimit($config);
 		$output .= static::buildLabel($name, $config);
 		if (!array_key_exists('skipInput', $config)) {
 			$output .= static::buildInput($content);
+		} else {
+			$output .= $content;
 		}
 
 		$output .= static::buildHint($config);
-		$output .= static::buildCharacterLimit($config);
 		$output .= static::buildDescription($name, $config);
 
 		$output .= '</div>';
@@ -180,16 +182,20 @@
 				);
 			}
 
-			protected static function buildCharacterLimit(array $config): string
-			{
-				if (empty($config['data']['limit'])) {
-					return '';
-				}
-				return sprintf(
-					'<span class="char-limit"><span class="current">0</span> / <span class="limit">%s</span></span>',
-					esc_html($config['data']['limit'])
-				);
-			}
+	protected static function buildCharacterLimit(array $config): string
+	{
+		$type = $config['type'] ?? 'text';
+		if (in_array($type, ['upload', 'gallery', 'selector'])) {
+			return '';
+		}
+		if (empty($config['maxlength'])) {
+			return '';
+		}
+		return sprintf(
+			'<span class="char-limit"><span class="current">0</span> / <span class="limit">%s</span></span>',
+			esc_html($config['maxlength'])
+		);
+	}
 
 		protected static function buildLabel(string $name, array $config):string
 		{
@@ -204,7 +210,7 @@
 			return '';
 		}
 
-		protected static function buildInput(string $content):string
+		public static function buildInput(string $content):string
 		{
 			return sprintf(
 				'<div class="field-input-wrapper">
@@ -512,7 +518,7 @@
 			$optionsHtml .= sprintf(
 				'<option value="%s"%s>%s</option>',
 				esc_attr($optValue),
-				selected($value, $optValue),
+				selected($value, $optValue, false),
 				esc_html($optLabel)
 			);
 		}
@@ -566,30 +572,47 @@
 
 	protected static function renderRadio(string $name, mixed $value, array $config): string
 	{
-		$options = $config['options'] ?? [];
+		$options    = $config['options'] ?? [];
+		$inputClass = !empty($config['inputClass']) ? ' class="' . esc_attr($config['inputClass']) . '"' : '';
+		$idPrefix   = $config['idPrefix'] ?? '';
 
 		$radios = sprintf(
 			'<fieldset>
-			<legend>%s%s</legend>',
+        <legend>%s%s</legend>',
 			array_key_exists('label', $config) ? esc_html($config['label']) : 'Select an option',
-			array_key_exists('required', $config) && $config['required']===true ? '<span class="required" aria-label="required">*</span>' : ''
+			array_key_exists('required', $config) && $config['required'] === true
+				? '<span class="required" aria-label="required">*</span>' : ''
 		);
 
-		foreach ($options as $optValue => $optLabel) {
+		foreach ($options as $optValue => $optConfig) {
+			if (is_array($optConfig)) {
+				$optLabel    = $optConfig['label'] ?? $optValue;
+				$optIcon     = $optConfig['icon'] ?? null;
+				$optDisabled = !empty($optConfig['disabled']) ? ' disabled' : '';
+			} else {
+				$optLabel    = $optConfig;
+				$optIcon     = null;
+				$optDisabled = '';
+			}
+
+			$labelContent = $optIcon
+				? jvbDashIcon($optIcon)
+				: '<span>' . esc_html($optLabel) . '</span>';
+
+			$optId = esc_attr($idPrefix . $name . '-' . $optValue);
+
 			$radios .= sprintf(
-				'
-                    <input type="radio" name="%s" id="%s-%s" value="%s"%s />
-				<label class="radio-option" for="%s-%s">
-                    <span>%s</span>
-                </label>',
+				'<input type="radio" name="%s" id="%s" value="%s"%s%s%s />
+            <label class="radio-option" for="%s" title="%s">%s</label>',
 				esc_attr($name),
-				esc_attr($name),
-				$optValue,
+				$optId,
 				esc_attr($optValue),
-				checked($value, $optValue),
-				esc_attr($name),
-				$optValue,
-				esc_html($optLabel)
+				checked($value, $optValue, false),
+				$optDisabled,
+				$inputClass,
+				$optId,
+				esc_html($optLabel),
+				$labelContent
 			);
 		}
 
@@ -663,7 +686,7 @@
 				?? str_replace('_', ' ',$config['content']);
 		}
 		if ($config['limit'] > 0) {
-			$config['data']['limit'] = $config['limit'];
+			$config['data']['max-files'] = $config['limit'];
 		}
 
 		$attachmentIds = static::parseIds($value);
@@ -709,7 +732,8 @@
 
 		$input .= '<div class="file-error"></div>';
 		$input .= jvbRenderProgressBar('', false, true, true);
-		$input .= '</div>';
+
+		$input .= '</div>'; // closes .file-upload-wrapper
 
 		if ($config['destination'] === 'post_group') {
 			$input .= static::renderUploadGroupAreaStart($config, $plural, $singular);
@@ -720,6 +744,7 @@
 			$input .= static::renderUploadGroupAreaEnd($config, $plural, $singular);
 		}
 
+		$input .= '</div>'; // closes .file-upload-container
 		unset($config['description']);
 		unset($config['label']);
 		return static::fieldWrap($name, $input, $config);
@@ -1181,6 +1206,7 @@
 			$plural[1]??''
 		);
 
+		$config['type'] = 'selector';
 		unset($config['label']);
 		unset($config['description']);
 		unset($config['hint']);
@@ -1251,7 +1277,7 @@
 						$plural = $taxonomy->labels->name;
 					}
 					$attr = sprintf(
-						' data-taxonomy="%s" data-single="%s" data-plural="%s',
+						' data-taxonomy="%s" data-single="%s" data-plural="%s"',
 						$config['taxonomy'],
 						$single,
 						$plural
@@ -1270,7 +1296,7 @@
 						$plural = $postType->labels->name;
 					}
 					$attr = sprintf(
-						' data-content="%s" data-single="%s" data-plural="%s',
+						' data-content="%s" data-single="%s" data-plural="%s"',
 						$config['content'],
 						$single,
 						$plural
@@ -1290,7 +1316,7 @@
 						$plural = 'Users';
 					}
 					$attr = sprintf(
-						' data-user="%s" data-single="%s" data-plural="%s',
+						' data-user="%s" data-single="%s" data-plural="%s"',
 						$config['user'],
 						$single,
 						$plural
@@ -1318,7 +1344,7 @@
 				$dataAttrs[] = 'data-selected="'.esc_attr(implode(',',$selected)).'"';
 			}
 			if ($config['autocomplete']) {
-				$dataAttrs[] = 'autocomplete';
+				$dataAttrs[] = 'data-autocomplete';
 			}
 			if (array_key_exists('hidden', $config) && $config['hidden']) {
 				$dataAttrs[] = 'hidden';
@@ -1335,15 +1361,18 @@
 				jvbIcon('plus-square')
 			);
 		}
-		protected static function buildSelectorAutocomplete(string $name, array $config):string
-		{
-			return sprintf(
-			'<input type="hidden" id="%s-autocomplete" autocomplete="off" data-ignore data-autocomplete>
-				<p class="message" hidden aria-live="polite">{ <span>Loading items</span> }</p>
-				<div class="auto-wrapper" hidden><ul class="search-results"></ul><button class="submit-term" hidden data-ignore><strong>Create: </strong> "<span></span>"</button></div>',
-				$name
-			);
-		}
+	protected static function buildSelectorAutocomplete(string $name, array $config): string
+	{
+		$containerId = sprintf('%s-%s-selector', $name, $config['subtype'] ?? $config['type']);
+		return sprintf(
+			'<input type="hidden" name="%s" value="">
+        <input type="search" id="%s-autocomplete" autocomplete="off" data-ignore data-autocomplete>
+        <p class="message" hidden aria-live="polite">{ <span>Loading items</span> }</p>
+        <div class="auto-wrapper" hidden><ul class="search-results"></ul><button class="submit-term" hidden data-ignore><strong>Create: </strong> "<span></span>"</button></div>',
+			esc_attr($containerId),
+			esc_attr($name)
+		);
+	}
 
 	protected static function renderTaxonomy(string $name, mixed $value, array $config): string
 	{
@@ -1648,12 +1677,13 @@
 
 		foreach ($fields as $fieldName => $fieldConfig) {
 			$fieldValue = $values[$fieldName] ?? '';
-			$fullName = "{$name}:{$fieldName}";
+			$fullName = array_key_exists('wrap', $config) ? $fieldName : "{$name}:{$fieldName}";
 			$output .= static::render($fullName, $fieldValue, $fieldConfig);
 		}
 
 		$output .= sprintf('</%s>', esc_attr($wrapper));
 
+		unset($config['label']);
 		return static::fieldWrap($name, $output, $config);
 	}
 

--
Gitblit v1.10.0