• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
How to create an ACP option with unlimited entries

How to create an ACP option with unlimited entries

A stylish alternative to a simple textbox, stored in an array

katsulynx

Well-known member
#1
katsulynx submitted a new resource:

How to create an ACP option with unlimited entries - A stylish alternative to a simple textbox, stored in an array

Table of Contents
  1. Introduction
  2. Requirements
  3. Basic Setup
  4. Step 1: Creating A New Option
  5. Step 2: Creating A New Admin Template
  6. In-Depth Explanations & Additions
    1. Data-Type: Array
    2. Admin Template: Foreach-Loop
    3. Admin Template: Styling
    4. Altering The Entry Field Scheme

Introduction

View attachment 111721

Ever had a look...
Read more about this resource...
 

Hoffi

Well-known member
#2
A good solution, but can improve the template with the following:

Simple Change OPTIONID to this:

HTML:
{$preparedOption.option_id}
and instead of option[OPTIONID] better use

HTML:
{$fieldPrefix}[{$preparedOption.option_id}]
Than add at the start
HTML:
<xen:controlunit label="{$preparedOption.title}">
to use the original Name of the option.

and at least bette delete this:
HTML:
<xen:if is="{$debugMode}">
<a href="admin.php?options/edit-option/OPTIONID" class="optionEditLink inputSupplementary Tooltip" data-offsetx="5" data-offsety="-8" data-tipclass="flipped"><span class="editText">{xen:phrase text}</span></a>
</xen:if>
and replace it with this:

HTML:
{xen:raw $editLink}
to let the controller display the Icon.

Than, add this before closing the option.

HTML:
<p class="explain">{xen:raw $preparedOption.explain}</p>

So, that we get thie Template at the end:

HTML:
<xen:controlunit label="{$preparedOption.title}">
    <ul class="FieldChoices">
        <xen:foreach loop="$preparedOption.option_value" key="$choice" value="$text">
            <xen:if is="{$text}">
                <li>
                    <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][]" value="{$text}" class="textCtrl" placeholder="{xen:phrase text}" size="25" />
                </li>
            </xen:if>
           </xen:foreach>
              <li>
            <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][]" class="textCtrl" placeholder="{xen:phrase text}" size="25" />
           </li>
    </ul>
    <input type="button" value="{xen:phrase add_additional_choice}" class="button smallButton FieldAdder" data-source="ul.FieldChoices li" />

    <p class="explain">{xen:raw $preparedOption.explain}</p>
    {xen:raw $editLink}
</xen:controlunit>
Now, you can use this Template without changes for every returning Option, if you use this multiple times.
 
Last edited:

Cyb3r

Well-known member
#4
Hello @katsulynx, I have been trying all day long to make more text fields without no luck.

I'm trying to add 5 text fields (id, title, img, user, group), can you please give an example on how to make this work?

Thanks in advance!