Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

338
Vistas
Selectize form validation - find out if an option has been chosen?

I'm using selectize for my drop down menus and I'm trying to do form validation. Each of the menus has class .code_select, and I want to know if an option has been selected on all of them. My code should determine if something is selected, and if not add the ID of the dropdown to an array called empty_fields. However, my dropdowns are all ending up in the array whether they have a selected option or not. This is my code:

$(".code_select").each(function(){
   if ($(this).find('option:selected').length === 0) {
       empty_fields.push($(this).attr("id")+'-selectized');
       submitForm=false;
     }                
});

An example of one of the inputs:

<div class='col-4'>
     <input type='text' class='form-control code_select' id='5-tree-Betpap-stdCodeSelect' name='5-tree-Betpap-stdCode' aria-label='Tree Metric Field 5  Standard Code select'>
</div> 

And my selectize initialization:

// initialize newCodes selectize control      
   newCodesSelect[index] = $(this).selectize({         
        valueField: 'id',
        labelField: 'label',
        create: false,
        hideSelected: false,
        options: listOptions[listType],          
        searchField: 'label',
        placeholder: "Choose " + listType + " codes (type to search)",
        maxItems: 1,
            });
     //This stores the selectize object to a variable
     newCodesSelectize[index] = newCodesSelect[index][0].selectize;                      

How do I determine if the select is still on the "placeholder" when my placeholder has a variable?

Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

OK, this is what worked for me. I had to use .selectize-control as the selector and find if any of the elements have data-attribute=null.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda