| | |
| | | $value = ''; |
| | | } |
| | | if (!empty($config['hidden'])) { |
| | | return ''; |
| | | if ($config['type'] !== 'upload') { |
| | | return static::renderHidden($name, $value, $config); |
| | | } |
| | | return ''; |
| | | } |
| | | |
| | | $type = $config['type'] ?? 'text'; |
| | |
| | | $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); |
| | |
| | | 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; |
| | |
| | | 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> |
| | |
| | | ); |
| | | |
| | | $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( |
| | |
| | | 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) { |
| | |
| | | $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'), |
| | | ); |
| | | } |
| | | |
| | | /** |