> For the complete documentation index, see [llms.txt](https://docs.stylemixthemes.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stylemixthemes.com/nuxy/registering-field.md).

# 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:

![](https://2194051268-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MPJdxe1K-sVbh8qB1ld%2F-MQWBpESdgRTc__CtUsI%2F-MQWEF4Wqt6cjPeZXNyO%2Fimage.png?alt=media\&token=c083aa52-d6ec-49ab-bff5-26267cb85805)

And file structure:

![](https://2194051268-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MPJdxe1K-sVbh8qB1ld%2F-MQWBpESdgRTc__CtUsI%2F-MQWEKmt5yCtF9Xr-oOr%2Fimage.png?alt=media\&token=9c8aab1a-b88a-4882-a010-9dbb5ae09b34)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
