Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

344
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!