I don't think you can with Rails (well, you could do it with validation on
the model) but it's easy enough with jQuery.
Assuming you have a text box like this:
<select name="Test" id="Test" multiple size="1">
<option value="option1">option1</option>
<option value="option2">option2</option>
<option value="option3">option3</option>
<option value="option4">option4</option>
<option value="option5">option5</option>
<option value="option6">option6</option>
<option value="option7">option7</option>
</select>
You can do this:
<script type='text/javascript'>
if ($('#Test').val().length > 5)
('#submit').hide();
}
</script>
Or take whatever action you want, but basically $(sel).val() returns an
array for multiple select boxes.
Cheers,
Andy
--
Andy Jeffries
http://andyjeffries.co.uk/ #rubyonrails #mysql #jquery
Registered address: 64 Sish Lane, Stevenage, Herts, SG1 3LS
Company number: 5452840
On 23 February 2010 22:30, Vincent P <[email protected]> wrote:
> How can I limit the number of selections in multiple select? Say, a
> user should not be able to select more than 5 values in a multiple
> selection box. I am following the multiple select example here:
>
> http://www.gilluminate.com/2007/02/15/best-way-to-do-multiple-select-combo-boxes-in-rails/
> . Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.