Skip to content

Redo SingleChoiceSelection for better differentiation between required and optional selections#222

Merged
patritzenfeld merged 12 commits intomainfrom
required-dropdowns
Apr 1, 2026
Merged

Redo SingleChoiceSelection for better differentiation between required and optional selections#222
patritzenfeld merged 12 commits intomainfrom
required-dropdowns

Conversation

@patritzenfeld
Copy link
Copy Markdown
Member

@patritzenfeld patritzenfeld commented Mar 31, 2026

  • forces a non-empty input for required dropdown selections
  • allows for directly optional dropdowns and radio buttons, thus removing the need to add --- options manually

@patritzenfeld patritzenfeld linked an issue Mar 31, 2026 that may be closed by this pull request
@github-actions

This comment has been minimized.

@patritzenfeld patritzenfeld marked this pull request as ready for review April 1, 2026 09:46
@patritzenfeld patritzenfeld merged commit 14342ca into main Apr 1, 2026
24 checks passed
@patritzenfeld patritzenfeld deleted the required-dropdowns branch April 1, 2026 13:22
Choose one or abstain
</label>
<select id="flexident1" ...>
<option value="None" selected>
Copy link
Copy Markdown
Contributor

@horriblename horriblename Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be value=""

so I can make use of <select required> to get the browser's own pre-submit checks like this:

Image

https://stackoverflow.com/a/6048891

Copy link
Copy Markdown
Member Author

@patritzenfeld patritzenfeld Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should already be the case if you use SingleChoiceSelection. This value="None" is only offered for form type Maybe SingleChoiceSelection. If the field is required, then this is used instead:

$newline never
<select ##{theId} name=#{name} :req:required *{attrs}>
$if req
<option value="" selected disabled>_{MsgSelectNone}
^{inside}

But I guess I should revise my custom selectField function to be less confusing. I just did a quick copy and edit on the standard Yesod version which resulted in messy code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently, with formify (Nothing @SingleChoiceSelection), I'll get a dropdown where the value defaults to the first real value, and the None option is disabled:

Image

I want it to default to None instead (the table is big so making it default to None makes it easy for students to see which dropdown they have not yet answered), but I also want the required check to take effect.

For this to work, perhaps what I need is just removing disabled from https://github.com/fmidue/flex-tasks/pull/222/changes#diff-26588820d6d6d6eb9930e0b89192489214299acf12c3b5043f1b362e02333b7bR774? what do you think ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I guess the behaviour is different between browsers. It did initially select the None option when I tried it on my setup, but did not allow reselecting it. I I will just remove the disabled attribute then.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What browser are you using? I'd like to take a look at this again on Tuesday.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

firefox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: required attribute and empty choice for dropdown

2 participants