A
A
AntonVir2020-12-24 05:14:03
HTML
AntonVir, 2020-12-24 05:14:03

How to disable form submission when select is empty?

The question is probably stupid, please do not kick much, I'm just learning. Tell me, please, there is a registration form where you need to select the name of the organization in the select field, where a bunch of different options are offered. I need the select field to be empty by default when hitting the form, and so that the form submission is not possible.

The first part of the task is implemented, the select field is empty by default, but the form is still sent with an empty name of the organization.

I have the following twig file with the following piece of code:

<label>{{ _('Организация') }}*</label> 

      <select  class="{% if widget.organization_error %} is-invalid-input{% endif %}" required  name="organization"> 
        {% for b in ncd_config.getBanksNames() %}
          <option hidden selected></option>
          <option value="{{b.name}}">{{b.name}}</option>
        {% endfor  %}
      </select>
      
      {% if widget.organization_error %}<span class="form-error is-visible">{{ widget.organization_error }}</span>{% endif %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-12-24
@AntonVir

try changing the first option (hidden and selected is a strange combination). I believe that you meant to write disabled.
Try to do so.

<option value="" selected disabled> Выберите что-то там... </option>

Example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question