elclanrs / jq-idealforms-old

The ultimate framework for building and validating responsive HTML5 forms.
665 stars 95 forks source link

Validation for dropdown list (select) #161

Closed jitendraV closed 11 years ago

jitendraV commented 11 years ago

Hello, I am fetching the category dynamically and displaying in the dropdown. So i need validation if no category selected.

This is my view

      <select name="category" id="category" class="small-input category">
          <option value="">&ndash; Select a Category &ndash;</option>
    <?php foreach($category as $cat) {  ?>
          <option  value="<?php echo $cat->category_id;?>" <?php if(isset($customer_req_act->category) && !empty($customer_req_act->category) && ($customer_req_act->category==$cat->category_id)) {?>selected<?php } ?>><?php echo $cat->category; ?></option>
    <?php } ?>  
      </select>

Validation

'Subcategory[]': { filters: 'exclude', data: { exclude: ['default'] }, errors : { exclude: 'Select Subcategory.' } },

Please suggest where am doing wrong. Thanx.

elclanrs commented 11 years ago

Check the example on the documentation https://github.com/elclanrs/jq-idealforms#example.

You can see how it's setup, you need to use the exclude filter with the value of the default option, typically default:

<select name="categories">
<option value="default">Select a Category</option>
<?php // dynamic options ?>
</select>

Options in the plugin:

'categories': {
  filters: 'exclude',
  data: { exclude: ['default'] },
  errors: { exclude: 'Choose a category from the list.' }
},