-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple instances of the same form get cascading ID #1558
Comments
I think the {{ myForm.render({
- attributes: {
+ id: "form-1",
+ fieldIdPrefix: 'myform-1-',
- }
}) }}
{{ myForm.render({
- attributes: {
+ id: "form-2",
+ fieldIdPrefix: 'myform-2-',
- }
}) }}
|
Hi @jannisborgers {{ myForm.render({
id: "form-1",
fieldIdPrefix: 'myform-1-',
}) }}
{{ myForm.render({
id: "form-2",
fieldIdPrefix: 'myform-2-',
}) }} did not work for me: no IDs are set for the multiple-form instances. |
In the V5 doc, I see:
None of them works for me. The first one injects no ID in the form and the second one makes ID cascading from form to form. |
Hi @scandella, Sorry for the delay...
The correct approach should be: <h1>First Instance of Form</h1>
{{ freeform.form("myFormHandle").render({
attributes: {
id: "form-one",
},
fieldIdPrefix: 'myform-one-',
}) }}
<h1>Second Instance of Form</h1>
{{ freeform.form("myFormHandle").render({
attributes: {
id: "form-two",
},
fieldIdPrefix: 'myform-two-',
}) }} In my testing, this works for the most part. I can, however, duplicate the issue where the second form gets |
@kjmartens
But "aField" of Form 2 always displays "foo", instead of "bar". Thanks for your help, I'm stuck on a project with that problem. |
Form IDs work with When referencing a specific field by it’s handle, it only works with Label attributes do not work with multiple forms, though. When including the same form, once the form has been rendered, the new form options seem to be ignored: This template: {% set form = freeform.form("formHandle") %}
{% set changeHandle = false %}
{% for index, item in 0..1 %}
{# Dump to compare #}
{{ d("changeHandle:", changeHandle) }}
{# Define formOptions #}
{% set formOptions = {
fields: {
"email": {
label: changeHandle == false ? "foo" : "bar",
}
}
} %}
{# Dump options #}
{{ d("formOptions:", formOptions) }}
{{ d("label:", formOptions.fields.email.label) }}
{# Render form #}
{{ form.render(formOptions) }}
{# Switch handle after 2 iterations #}
{% if index == 0 %}
{% set changeHandle = true %}
{% endif %}
<hr>
{% endfor %} |
Thanks @jannisborgers for confirming the problem. |
@jannisborgers |
With each instance getting is own ID now, I ended up replacing the label text with some JS. Not ideal… |
What happened?
I display multiple Instances of the same form on one page.
The second form gets
id="form-1 form-2" fieldidprefix="myform-1- myform-2-"
, and so on for form 3, 4…There is no way to add different attributes for the same field to the various instances: they all get the same attributes as the first one.
Errors and Stack Trace (if available)
No response
How can we reproduce this?
Freeform Edition
Pro
Freeform Version
5.6.4
Craft Version
Craft Pro 4.12.5
When did this issue start?
No response
Previous Freeform Version
No response
The text was updated successfully, but these errors were encountered: