javascript - Rails Form Select Validation -


i want not accept <option value="">select one</option> in rails form.

this code:

<div class="field">     <p><%= f.label :category, "category:" %></p>     <%= f.select(:category, [["-- select 1 --", "false"],'analytics','commerce','content management','gaming','green','media','social media','technology - software','technology - hardware', 'web']) %> </div> 

with jquery validation plugin:

$(document).ready(function(){   $("input[name='commit']").click(function(){     $("#new_startup").validate({       rules: { startup[category]: { valuenotequals: "false" } },       messages: { startup[category]: { valuenotequals: "please select one" } }      });     if ($("#new_startup").valid())       location.href = "#";       $("#tag").css("display","none");       $("#thank-you").css("display","block");   }); }); 

this doesn't work though... there better method?

setting ["-- select 1 --", ""] didn't work either.

i believe want either prompt or include_blank in select.

<%= f.select(:category, ['analytics','commerce','content management','gaming','green','media','social media','technology - software','technology - hardware', 'web'], :include_blank => '-- select 1 --') %>

see docs more.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -