Make the test for max_selected_options happen _before_ the option
gets selected in the form field.

This fixes #977