User's Custom Field

Hello guys,

I have a table with:

ID
FieldType [text, combo, check]
Value

The idea is, on frontend, show the inputs accordingly to “field type” column.

I have some ideas in mind on how approach it, but would love to hear your approachs!

Thanks!

Hi,
We usually build all types of controls inside the repeat. And based on the value from DB, only one of them shows up in the UI.
The HTML rendered on the browser is not very elegant, but the UI is fine and UX too for the most part.
Unless you have too many repeats on the same page, this approach is the easiest and work great.

1 Like

Thanks Sid!!

Hi @sid , can you show an example of the code behind one of these repeats? Just curious.

I don’t have the exact code at hand right now. Here’s a sample I can think of:

Server Action:
NAME    TYPE
txt1    text   
ta1     textarea
sw1     switch
<div repeat="...">
    <input type="text" dmx-bind:name="name" dmx-show="type == 'text'" disabled="type != 'text'"/>
    <textarea dmx-bind:name="name" dmx-show="type == 'textarea'" disabled="type != 'textarea'"></textarea>
    <input type="checkbox" dmx-bind:name="name" dmx-show="type == 'switch'" disabled="type != 'switch'"/>
</div>

Setting up the value part is a bit tricky. For select/check/radio lists you will have to keep the values as comma separate for example.