xpertbot / craft-wheelform

Craft CMS 4 Form with Database integration
MIT License
66 stars 32 forks source link

identify groups of inputs against other #275

Closed wallythewebdev closed 2 years ago

wallythewebdev commented 2 years ago

Hi - Was just wondering if I can wrap some inputs together (when auto generating the form fields).

So, currently form items are being added in a wf-group div:

image

I was hoping to consolidate these into one wf-group?

I can do it if I add in the html field and create a div with a class:

image

This ends up putting them into the same div:

image

But this is not very neat and a pretty bad authoring experience if someone was to make some edits to the form in future - is there another way to do this?

Thanks for any help - W

xpertbot commented 2 years ago

Hello, You can use a mix of both simple rendering and advanced displaying. It can be something like:

{{ form.open() }}
    {% set count = 1 %}
    {% for field in form.fields %}
        {% switch field.name %}
            {% case "name" or "email" %}
                {% if count == 1 %}
                    <div class="field-group">
                {% endif %}
                {{ field.render() }}
                {% if count == 2 %}
                    </div>
                {% endif %}
                {% set count = count+1 %}
            {% default %}
                {{ field.render() }}
        {% endswitch %}

        {{ wheelformErrors[field.name] is defined ? errorList(wheelformErrors[field.name]) }}
    {% endfor %}
{{ form.close() }}

adjusted it to the number of fields and keep the fields together in the backend.

wallythewebdev commented 2 years ago

Amazing thanks for the super quick response like always :) I'll get cooking with this right away - could I also, open an idea for a feature request, of being able to group elements in the Plugin interface? Happy to dive into more detail if that helps:

Again thanks for the help :)

xpertbot commented 2 years ago

Hello, No problem, That's a common requested feature. It's a significant undertaking that's why it's been sitting on the backburner for now.

wallythewebdev commented 2 years ago

Gotcha - its a "nice to have" for sure - but if there is a hard code way of doing this as well then it doesn't break anything. Thanks again :)