Body: <p>I want to be able to check if a <code>form</code> object returned by a query has fields of a certain scope before I generate its markup.</p>
  <p>I have a test case where I want to know if a form has a <code>checkbox</code> field type in it, but I can't figure out how to query just the fields in the form with something like:</p>
  <pre><code>{% set hasCheckbox = form.fields.type('checkbox').one() ?? null %}
  </code></pre>
  <p>I know that doesn't work, so I've got a workaround, but it would be good to know if this kind of thing is possible.</p>
  <hr />
  <p>My workaround is to do something like:</p>
  <pre><code>{% set hasCheckbox = false %}
  {% set formMarkup  = [] %}
  
  {% for row in form %}
      {% for field in row %}
          {% set fieldMarkup %}
              {# Do stuff #}
          {% endset %}
  
          {% if field.type == 'checkbox' %}
              {% set hasCheckbox = true %}
          {% endif %}
  
          {% set formMarkup = formMarkup|merge([fieldMarkup])&quot; %}
      {% endfor %}
  {% endfor %}
  
  {# Do something with hasCheckbox #}
  {# Output formMarkup #}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-22T06:37:35.760Z
Comments.Text: Had you any joy with this? Currently after something similar myself.
Comments.UserDisplayName: mmc501
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-22T12:05:16.883Z
Comments.Text: Hi. Nope sorry. I had a private reply from Solspace that this is not possible at present, so the workaround approach above is the way to go. Sorry for not posting that here sooner.
Comments.UserDisplayName: Jonathan Schofield
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-22T12:06:04.860Z
Comments.Text: Thanks - will implement something similar to your solution.
Comments.UserDisplayName: mmc501
Tags: <plugin-freeform><solspace><elementquery><freeform>
Title: Freeform: query form object for presence of field type (or other criterion)
ThreadText: # Freeform: query form object for presence of field type (or other criterion)
  
  (Asked by: username_0 on 2020-08-19)
  
  I want to be able to check if a `form` object returned by a query has fields of a certain scope before I generate its markup.
  
  I have a test case where I want to know if a form has a `checkbox` field type in it, but I can't figure out how to query just the fields in the form with something like:
  
  ```
  {% set hasCheckbox = form.fields.type('checkbox').one() ?? null %}
  
  ```
  
  I know that doesn't work, so I've got a workaround, but it would be good to know if this kind of thing is possible.
  
  ---
  
  My workaround is to do something like:
  
  ```
  {% set hasCheckbox = false %}
  {% set formMarkup  = [] %}
  
  {% for row in form %}
      {% for field in row %}
          {% set fieldMarkup %}
              {# Do stuff #}
          {% endset %}
  
          {% if field.type == 'checkbox' %}
              {% set hasCheckbox = true %}
          {% endif %}
  
          {% set formMarkup = formMarkup|merge([fieldMarkup])" %}
      {% endfor %}
  {% endfor %}
  
  {# Do something with hasCheckbox #}
  {# Output formMarkup #}
  
  ```
  
  **Tags:** plugin-freeform, solspace, elementquery, freeform
  
  > **Comments:**
  > **username_1**: Had you any joy with this? Currently after something similar myself.  
  > **username_0**: Hi. Nope sorry. I had a private reply from Solspace that this is not possible at present, so the workaround approach above is the way to go. Sorry for not posting that here sooner.  
  > **username_1**: Thanks - will implement something similar to your solution.  
  
  ---
  
  ## 0 answers
  
  