Sure, the record does already exist. The user is redirected from the initial form to this “more information” conversational form. I am trying to load a single form that has all my fields, and then via javascript, control which fields are displayed to the user on each prompt.
Below is the code for my form builder, then I have all my questions stored in a twig collection called questions and all the logic and the content that is displayed for each page in a javascript object called “Pathways”. Basically there are 4 “starting point pathways” and each page after displays a different set of questions/messages based on the previous response. Many of these pathways reuse the same questions so I thought loading each question in a single form would be a better way to go. I also wanted to utilize “stay on same page after form submit” so we don’t possibly lose users each time the page reloads.
One solution that seems like it might work is renaming the input’s name attribute on submit so that it doesn’t map correctly to the record…. (although it throws a lot of warnings in the icds logs and a lot of my javascript rely’s on the name attribute)
There’s probably a much better way to do what I’m trying to do, and I’m all ears for it! Thanks
{# generate form #}
{% form entity="lead" keep=true keep-data=true mode="update" record=lead|to_entity_reference %}
<form id="get-started" method="post" enctype="multipart/form-data">
<h2 id="form-heading"></h2>
<p id="form-message"></p>
<div class="active-questions"></div>
<div class="inactive-questions">
{% for key, field in questions %}
<div class="form-group">
<label for="{{ field.name }}">{{ field.label }}</label>
{% if field.type == 'text' %}
<input type="text" name="{{ field.name }}" id="{{ field.name }}" class="form-control" />
{% elseif field.type == 'date' %}
<input type="date" name="{{ field.name }}" id="{{ field.name }}" class="form-control" />
{% elseif field.type == 'file' %}
<input type="file" name="{{ field.name }}" id="{{ field.name }}" class="form-control" />
{% elseif field.type == 'number' %}
<input type="number" name="{{ field.name }}" id="{{ field.name }}" class="form-control"
min="{{ field.min }}" max="{{ field.max }}" />
{% elseif field.type == 'textarea' %}
<textarea name="{{ field.name }}" id="{{ field.name }}" class="form-control"
rows="{{ field.rows }}"></textarea>
{% elseif field.type == 'radio' %}
<div class="{{field.class}}">
{% for option in field.options %}
<div class="form-check">
<input type="radio" name="{{ field.name }}" id="{{ field.name }}_{{ option.value }}"
value="{{ option.value }}" class="form-check-input" {% if option.selected %} checked {% endif %}
{% if option.hidden %} hidden {% endif %} {% if option.disabled %} disabled {% endif %} />
<label class="form-check-label" for="{{ field.name }}_{{ option.value }}">{{ option.label }}</label>
</div>
{% endfor %}
</div>
{% elseif field.type == 'checkbox' %}
{% for option in field.options %}
<div class="form-check">
<input type="checkbox" name="{{ field.name }}" id="{{ field.name }}_{{ option.value }}"
value="{{ option.value }}" class="form-check-input {{option.class}}" {% if option.selected %}
checked {% endif %} {% if option.hidden %} hidden {% endif %} {% if option.disabled %} disabled {%
endif %} />
<label class="form-check-label" for="{{ field.name }}_{{ option.value }}">{{ option.label }}</label>
</div>
{% endfor %}
{% elseif field.type == 'select' %}
<select name="{{ field.name }}" id="{{ field.name }}" class="form-control">
{% for option in field.options %}
<option value="{{ option.value }}" {% if option.selected %} selected {% endif %} {% if option.hidden %}
hidden {% endif %} {% if option.disabled %} disabled {% endif %}>{{ option.label }}
</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-nav">
<button type="button" id="prev-btn" class="btn btn-primary">Prev</button>
<button type="submit" id="next-btn" class="btn btn-primary">Next</button>
<button type="submit" id="submit-btn" class="btn btn-primary">Submit</button>
</div>
</form>
{% endform %}