16, 'element' => 'repeater_field', 'attributes' => array( 'name' => 'repeater_field', 'data-type' => 'repeater_field' ), 'settings' => array( 'label' => __('Repeater Field', 'fluentformpro'), 'admin_field_label' => '', 'container_class' => '', 'label_placement' => '', 'validation_rules' => array(), 'conditional_logics' => array(), 'max_repeat_field' => '' ), 'fields' => array( array( 'element' => 'input_text', 'attributes' => array( 'type' => 'text', 'value' => '', 'placeholder' => '', ), 'settings' => array( 'label' => __('Column 1', 'fluentformpro'), 'help_message' => '', 'validation_rules' => array( 'required' => array( 'value' => false, 'global' => true, 'message' => Helper::getGlobalDefaultMessage('required'), 'global_message' => Helper::getGlobalDefaultMessage('required'), ) ) ), 'editor_options' => array(), ) ), 'editor_options' => array( 'title' => __('Repeat Field', 'fluentformpro'), 'icon_class' => 'ff-edit-repeat', 'template' => 'fieldsRepeatSettings' ), ]; } public function getGeneralEditorElements() { return [ 'label', 'label_placement', 'admin_field_label', 'fields_repeat_settings', ]; } public function getAdvancedEditorElements() { return [ 'container_class', 'name', 'conditional_logics', 'max_repeat_field' ]; } public function getEditorCustomizationSettings() { return [ 'fields_repeat_settings' => array( 'template' => 'fieldsRepeatSettings', 'label' => __('Repeat Field Columns', 'fluentformpro'), 'help_text' => __('Field Columns which a user will be able to repeat.', 'fluentformpro'), ) ]; } /** * Compile and echo the html element * @param array $data [element data] * @param stdClass $form [Form Object] * @return void */ public function render($data, $form) { $elementName = $data['element']; $data = apply_filters_deprecated( 'fluentform_rendering_field_data_' . $elementName, [ $data, $form ], FLUENTFORM_FRAMEWORK_UPGRADE, 'fluentform/rendering_field_data_' . $elementName, 'Use fluentform/rendering_field_data_' . $elementName . ' instead of fluentform_rendering_field_data_' . $elementName ); $data = apply_filters('fluentform/rendering_field_data_' . $elementName, $data, $form); // Test implementation using address component $rootName = $data['attributes']['name']; $hasConditions = $this->hasConditions($data) ? 'has-conditions ' : ''; @$data['attributes']['class'] .= ' ff-el-group ' . $this->wrapperClass . ' ' . $hasConditions . ' ' . ArrayHelper::get($data, 'settings.container_class'); $data['attributes']['class'] = trim($data['attributes']['class']); $maxRepeat = ArrayHelper::get($data, 'settings.max_repeat_field'); $data['attributes']['data-max_repeat'] = $maxRepeat; $data['attributes']['data-root_name'] = $rootName; if ($labelPlacement = ArrayHelper::get($data, 'settings.label_placement')) { $data['attributes']['class'] .= ' ff-el-form-' . $labelPlacement; } $atts = $this->buildAttributes( \FluentForm\Framework\Helpers\ArrayHelper::except($data['attributes'], 'name') ); $fields = $data['fields']; ob_start(); ?>
> buildElementLabel($data, $form); ?>
$item): $itemLabel = $item['settings']['label']; $item['settings']['label'] = ''; $item['attributes']['aria-label'] = 'repeater level 1 and field ' . $itemLabel; $item['attributes']['name'] = $rootName . '[0][]'; $item['attributes']['id'] = $this->makeElementId($data, $form) . '_' . $key; $item['attributes']['data-repeater_index'] = $key; $item['attributes']['data-type'] = 'repeater_item'; $item['attributes']['data-name'] = $rootName.'_'.$key.'_0'; $item['attributes']['data-error_index'] = $rootName.'['.$key.']'; $item['attributes']['data-default'] = ArrayHelper::get($item, 'attributes.value'); ?>
buildElementLabel($field, $form); ?>
getRepeater($data['element']); ?>
'; $div .= ''; $div .= ''; $div .= ''; return $div; } return ''; } public function renderResponse($response, $field, $form_id) { if (defined('FLUENTFORM_RENDERING_ENTRIES')) { return __('....', 'fluentformpro'); } if (is_string($response) || empty($response) || !is_array($response)) { return ''; } $fields = ArrayHelper::get($field, 'raw.fields'); $columnCount = (count($fields) > count((array)$response[0])) ? count($fields) : count((array)$response[0]); $columns = array_fill(0, $columnCount, 'column'); if (defined('FLUENTFORM_DOING_CSV_EXPORT')) { return self::getResponseAsText($response, $fields, $columns); } return $this->getResponseHtml($response, $fields, $columns); } protected function getResponseHtml($response, $fields, $columns) { ob_start(); ?>
$count): ?> $item): ?> $count): ?>
count((array)ArrayHelper::get($response, 0))) ? count($fields) : count((array)ArrayHelper::get($response, 0)); $columns = array_fill(0, $columnCount, 'column'); } $totalColumns = count($columns); $text = ''; foreach ($columns as $index => $count) { $text .= trim(ArrayHelper::get($fields, $index . '.settings.label', ' ')); if( $index+1 != $totalColumns ) { $text .= " | "; } } $text .= "\n"; foreach ($response as $responseIndex => $item): foreach ($columns as $index => $count): $text .= ArrayHelper::get($item, $index); if( $index+1 != $totalColumns ) { $text .= " | "; } endforeach; $text .= "\n"; endforeach; return $text; } }