PloneFormGen: How to not have input from optional SelectionField

The default behaviour for FormSelectionFields seems to be to show one of the available options.

So if the field is set as "optional" and my options are:

  • Mr
  • Miss
  • Mrs

I expect something like this might be shown:

  • Select one
  • Mr
  • Miss
  • Mrs

Where Select one is not counted as input (it gets filtered out).

Because of the current behaviour, if I do nothing I end up with Mr showing up as the value for my SelectionField.

Here's what I ended up doing:
It's very basic and naive but works

  1. intercepts my form submission
  2. locates my select field
  3. checks if it is set to the value "Choose one" which should be true if they didn't select something
  4. sets the value of my select field to ""
  5. continues the form submission
require(["jquery"], function($) {
    $(document).ready(function(){
    $(function() {
        $(document).on('submit', 'form#fg-base-edit', function() {
            if ($("#prefix").val() === "Choose one") {
                $("#prefix").val("");
            }
            return true;

        });
    });
    });
});

Integrating it into my site
I added the code above to as a js file in my theme and created a Diazo rule which only includes the js in the specific form. This may be overengineering but the snippet to included the js was added as a rapido block. This has become my practice because some characters in the path break the xsl in my rules.xml and I this is my work around to overcome that.

I'm sure I could use the resource registry but I often think about it after the fact.