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 | 89 +++++++++++++++++++++++++++++++-------------
1 files changed, 62 insertions(+), 27 deletions(-)
diff --git a/inc/meta/Form.php b/inc/meta/Form.php
index 2cf3f05..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';
@@ -53,12 +56,19 @@
/**
* Render complete form from Meta instance
*/
- public static function renderFormFrom(Meta $meta, string $endpoint, array $options = []): string
+ public static function renderFormFrom(Meta $meta, string $endpoint, array $options = [], array $fields = []): string
{
$id = $options['form-id'] ?? $endpoint;
$classes = isset($options['classes']) ? ' class="' . implode(' ', $options['classes']) . '"' : '';
+ $formID = isset($options['showFormID']) && $options['showFormID']!== false;
- $output = '<form id="' . esc_attr($endpoint) . '"' . $classes . ' data-save="' . esc_attr($endpoint) . '" data-form-id="' . esc_attr($id) . '">';
+ $output = sprintf(
+ '<form id="%s"%s data-save="%s"%s>',
+ esc_attr($endpoint),
+ $classes,
+ esc_attr($endpoint),
+ $formID ? ' data-form-id="'.esc_attr($id).'"' : '',
+ );
if (!empty($options['heading'])) {
$output .= '<h2>' . esc_html($options['heading']) . '</h2>';
@@ -71,8 +81,11 @@
}
}
- foreach ($meta->configs() as $name => $config) {
- $output .= static::render($name, $meta->get($name), $config);
+ $allFields = $meta->getAll($fields);
+
+ foreach ($allFields as $name => $value) {
+ $config = $meta->config($name);
+ $output .= static::render($name, $value, $config);
}
if (!empty($options['submit'])) {
@@ -310,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;
@@ -350,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>
@@ -556,17 +584,17 @@
$checked = in_array($optValue, $values) ? ' checked' : '';
$checkboxes .= sprintf(
'
- <input type="checkbox" name="%s[]" id="%s-%s" value="%s"%s />
+ <input type="checkbox" name="%s" id="%s-%s" value="%s"%s/>
<label class="checkbox-option" for="%s-%s">
<span>%s</span>
</label>',
esc_attr($name),
esc_attr($name),
- $optValue,
+ esc_attr($optValue),
esc_attr($optValue),
$checked,
esc_attr($name),
- $optValue,
+ esc_attr($optValue),
esc_html($optLabel)
);
}
@@ -1626,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(
@@ -1647,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) {
@@ -1676,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'),
+ );
}
/**
@@ -1705,7 +1740,7 @@
foreach ($fields as $fieldName => $fieldConfig) {
$fieldValue = $values[$fieldName] ?? '';
- $fullName = array_key_exists('wrap', $config) ? $fieldName : "{$name}:{$fieldName}";
+ $fullName = "{$name}|{$fieldName}";
$output .= static::render($fullName, $fieldValue, $fieldConfig);
}
@@ -1719,7 +1754,7 @@
{
return sprintf('<dialog id="jvb-selector" aria-labelledby="modal-title" aria-modal="true">
<div class="wrap col">
- <header class="modal-header">
+ <header class="row">
<h3 id="modal-title">Select Taxonomy</h3>
</header>
@@ -1813,13 +1848,13 @@
<template class="selectedTerm">
<div class="selected-item row">
<span class="item-name"></span>
- <button type="button" class="remove-term row">%s</button>
+ <button type="button" class="remove-term">%s</button>
</div>
</template>
<template class="termBreadcrumb">
<button type="button" class="path-level"></button>
</template>',
- static::search('Search terms', 'search-terms'),
+ str_replace('class="search-container', 'class="open search-container', static::search('Search terms', 'search-terms')),
jvbModalActions(),
jvbIcon('plus-square'),
jvbIcon('x')
--
Gitblit v1.10.0