From 715e26a9eb219808d5c899d418e1d596f9318f61 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 22 Jun 2026 16:59:19 +0000
Subject: [PATCH] =Debugging and implementing the Checkout.js logic. Will be uploading to test integration with square next.

---
 inc/meta/Form.php |   61 +++++++++++++++++++++---------
 1 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/inc/meta/Form.php b/inc/meta/Form.php
index dec811f..9c2f926 100644
--- a/inc/meta/Form.php
+++ b/inc/meta/Form.php
@@ -26,7 +26,10 @@
 			$value = '';
 		}
 		if (!empty($config['hidden'])) {
-			return '';
+            if ($config['type'] !== 'upload') {
+                return static::renderHidden($name, $value, $config);
+            }
+            return '';
 		}
 
 		$type = $config['type'] ?? 'text';
@@ -77,9 +80,9 @@
 				$output .= '<p>' . esc_html($d) . '</p>';
 			}
 		}
-		error_log('[Form]::renderFormFrom getting fields: '.print_r($fields, true));
+
 		$allFields = $meta->getAll($fields);
-		error_log('[Form]::renderFormFrom field values: '.print_r($allFields, true));
+
 		foreach ($allFields as $name => $value) {
 			$config = $meta->config($name);
 			$output .= static::render($name, $value, $config);
@@ -320,6 +323,15 @@
 		return static::fieldWrap($name, $input, $config);
 	}
 
+    protected static function renderHidden(string $name, mixed $value, array $config):string
+    {
+        return sprintf(
+            '<input type="hidden" name="%s" value="%s">',
+            esc_attr($name),
+            esc_attr($value)
+        );
+    }
+
 	protected static function renderTextarea(string $name, mixed $value, array $config): string
 	{
 		$rows = $config['rows'] ?? 5;
@@ -360,13 +372,19 @@
 		if (!array_key_exists('class', $config)) {
 			$config['class']=[];
 		}
-		$config['class'][] ='quantity-input';
+		$config['class'][] = 'quantity-input';
+        $config['class'][] = 'row';
+        $config['class'][] = 'nowrap';
+
+        if (array_key_exists('isCart', $config) && $config['isCart'] === true) {
+
+        }
 
 		$attrs = static::inputAttrs($name, $config);
 
 		$value = ($value !== '') ? ' value="'.esc_attr($value).'"' : '';
 		$input = sprintf(
-			'<div class="quantity">
+			'<div class="row nowrap">
 				<button type="button" class="decrease" title="%s" aria-label="Decrease %s">%s</button>
 				<input type="number"%s%s />
 				<button type="button" class="increase" title="%s" aria-label="Increase %s">%s</button>
@@ -1636,16 +1654,21 @@
 		);
 
 		$input .= '<div class="repeater-items">';
-		$rowTitle = array_key_exists('new_row', $config) ? $config['new_row'] : 'New Item';
+
+        $hasTitle = array_key_exists('row_label', $config);
 		if(!empty($rows)) {
 			foreach ($rows as $index=>$row) {
-				$input .= static::renderRepeaterRow($config['fields'], $row, $index, $name, $rowTitle);
+                $titleReference = $hasTitle ? $config['row_label'] : null;
+                $rowTitle = !is_null($titleReference) ? $row[$titleReference] : 'New Item';
+
+				$input .= static::renderRepeaterRow($config['fields'], $row, $index, $name, $rowTitle, $titleReference);
 			}
 		}
 		$input .= '</div>';
 
+        $titleReference = $hasTitle ? $config['row_label'] : null;
 		$input .= '<template class="'.uniqid('repeaterRow').'">';
-			$input .= static::renderRepeaterRow($config['fields'], [], '','',$rowTitle);
+			$input .= static::renderRepeaterRow($config['fields'], [], '','','New Item', $titleReference);
 		$input .= '</template>';
 
 		$input .= sprintf(
@@ -1657,27 +1680,25 @@
 		unset($config['label']);
 		return static::fieldWrap($name, $input, $config);
 	}
-		protected static function renderRepeaterRow(array $fields, array $values, int|string $index, string $name, string $rowTitle='New Item'):string
+		protected static function renderRepeaterRow(array $fields, array $values, int|string $index, string $name, string $rowTitle='New Item', ?string $rowTitleField = null):string
 		{
 			$displayNumber = (is_string($index)) ? $index : ($index +1);
 
+
 			$output = sprintf(
-				'<div class="repeater-row" data-index="%s">
-						<button type="button" class="remove-row" title="Remove">
-							%s
-						</button>
+				'<div class="repeater-row row nowrap" data-index="%s">
+                        <span class="drag-handle row">%s</span>
 						<details%s>
 							<summary class="row x-btw repeater-row-header">
-								<span class="drag-handle">%s</span>
 								<span class="row-number">#%s</span>
-								<span class="row-title">%s</span>
+								<span class="row-title"%s>%s</span>
 							</summary>
 							<div class="repeater-row-content">',
 				esc_attr($index),
-				jvbIcon('trash'),
+                jvbIcon('dots-six-vertical'),
 				is_string($index) ? ' open' : '',
-				jvbIcon('dots-six-vertical'),
 				$displayNumber,
+                is_null($rowTitleField) ? '' : 'data-label="'.$rowTitleField.'"',
 				$rowTitle
 			);
 			foreach ($fields as $fieldName => $fieldConfig) {
@@ -1686,7 +1707,11 @@
 				$output .= static::render($fullName, $fieldValue, $fieldConfig);
 			}
 
-			return $output.'</div></details></div>';
+			return $output.sprintf('</div></details><button type="button" class="remove-row" title="Remove">
+							%s
+						</button></div>',
+                    jvbIcon('trash'),
+                );
 		}
 
 	/**

--
Gitblit v1.10.0