# Registering field

We have quite enough fields to use, but if you need something extra functional and you familiar with Vue and with Components you can make your own fields type.

Here we will explain how to create own field called Repeater

First of all, you should specify the directory to add a custom field template:

**my-plugin/my-own-fields/setup.php**

In your config file specify field type.

```
'awesome_field' => array(
    'type' => 'my_super_field',
    'label' => esc_html__('Simple Repeater', 'my-domain'),
    'value' => 'Awesome default value',
    'submenu' => esc_html__('General fields', 'my-domain'),
),
```

Now we have a new field type **my\_super\_field**

```
add_filter('wpcfto_field_my_super_field', function($path){

    return dirname(__FILE__) . '/my_super_field.php';

});
```

The framework will watch for the directory you specified above with template name my\_super\_field.php

In the template will be available certain variables : **/path/to/my-folder/my\_super\_field.php**

```
<?php

/**
 * @var $field
 * @var $field_id
 * @var $field_value
 * @var $field_label
 * @var $field_name
 * @var $section_name
 *
 */
```

**And we need to enqueue our component script**

```
wp_enqueue_script('my-super-component', plugin_dir_url(__FILE__) . '/js_components/my_super_field.js');
```

**�Now we need to create Component with Repeater Logic, encapsulated from the main app.**

```
<label v-html="<?php echo esc_attr($field_label); ?>"></label>

<my_super_component inline-template
                    v-on:get-super-mode="<?php echo esc_attr($field_value); ?> = $event"
                    v-bind:super_data="<?php echo esc_attr($field_value); ?>">

    <div class="super-awesome-component">

        <div v-for="(single_super, single_super_key) in data" class="row">
            <div class="column">
                <input type="text" v-model="data[single_super_key]"/>
            </div>
            <div class="column">
                <i class="fa fa-times"
                   v-bind:style="removeStyles"
                   @click="removeSuperSingle(single_super_key)" class="column"></i>
            </div>
        </div>

        <div class="button" @click="addSuperSingle">Add Super Field</div>

    </div>

</my_super_component>
```

Now we need to specify input field to store our setting

```
<!--Here We store actual value in hidden input-->
<!--Mostly it needed for metabox area, where WordPress saves field automatically after post update-->
<input type="hidden"
       name="<?php echo esc_attr($field_name); ?>"
       v-bind:placeholder="<?php echo esc_attr($field_label); ?>"
       v-bind:id="'<?php echo esc_attr($field_id); ?>'"
       v-model="<?php echo esc_attr($field_value); ?>"/>
```

�So final code in **/path/to/my-folder/my\_super\_field.php looks like:**

```
<?php

/**
 * @var $field
 * @var $field_id
 * @var $field_value
 * @var $field_label
 * @var $field_name
 * @var $section_name
 *
 */

wp_enqueue_script('my-super-component', plugin_dir_url(__FILE__) . '/js_components/my_super_field.js');

?>

<label v-html="<?php echo esc_attr($field_label); ?>"></label>

<my_super_component inline-template
                    v-on:get-super-mode="<?php echo esc_attr($field_value); ?> = $event"
                    v-bind:super_data="<?php echo esc_attr($field_value); ?>">

    <div class="super-awesome-component">

        <div v-for="(single_super, single_super_key) in data" class="row">
            <div class="column">
                <input type="text" v-model="data[single_super_key]"/>
            </div>
            <div class="column">
                <i class="fa fa-times"
                   v-bind:style="removeStyles"
                   @click="removeSuperSingle(single_super_key)" class="column"></i>
            </div>
        </div>

        <div class="button" @click="addSuperSingle">Add Super Field</div>

    </div>

</my_super_component>


<!--Here We store actual value in hidden input-->
<!--Mostly it needed for metabox area, where WordPress saves field automatically after post update-->
<input type="hidden"
       name="<?php echo esc_attr($field_name); ?>"
       v-bind:placeholder="<?php echo esc_attr($field_label); ?>"
       v-bind:id="'<?php echo esc_attr($field_id); ?>'"
       v-model="<?php echo esc_attr($field_value); ?>"/>
```

And our JS component file: **/path/to/my-folder/js\_components/my\_super\_field.js**

```
Vue.component('my_super_component', {
    props: ['super_data'],
    data: function () {
        return {
            data: [],
            removeStyles: {
                color: 'red',
                padding: '15px 10px'
            }
        }
    },
    mounted: function () {
        if (WpcftoIsJsonString(this.super_data)) {
            this.data = JSON.parse(this.super_data);
        } else {
            this.data.push(this.super_data);
        }

    },
    methods: {
        removeSuperSingle: function (index) {
            this.data.splice(index, 1);
        },
        addSuperSingle: function () {
            this.data.push('');
        }
    },
    watch: {
        data: function (value) {
            this.$emit('get-super-mode', JSON.stringify(value));
        }
    }
});
```

�Field looks like this now:

![](/files/-MQWEF4Wqt6cjPeZXNyO)

And file structure:

![](/files/-MQWEKmt5yCtF9Xr-oOr)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stylemixthemes.com/nuxy/registering-field.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
