After submiting the form "The value you selected is not a valid choice." error appears.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bogdan.stamate created an issue. See original summary.

snufkin’s picture

Title: The value you selected is not a valid choice. » "The value you selected is not a valid choice" error is thrown when using integer lists

This is only an issue when the list is not text, but integer. I've done some work around trying to make it work with list_integer, managed to get the new value added to the allowed values, but still fails the validation for some reason.

We are not going to use the module, so i can't contribute more, but here is my work so far: https://gist.github.com/snufkin/4a317a1135883d27aee38e846ff2e542

tlyngej’s picture

I experienced an error like this, but on a field that didn't use `select_or_other`.

https://www.drupal.org/node/2698213#comment-11212523

robpowell’s picture

I am receiving the same error message for all my select form elements even though I only use select_or_other on one field. If I uninstall the module, the errors do not show up.
Drupal version: 8.1.1 and select_or_other: 8.x-1.0-alpha2

legolasbo’s picture

Status: Active » Postponed (maintainer needs more info)
Related issues: +#2698213: List fields show error 'The value you selected is not a valid choice'

I tried to reproduce the issue, but have been unable to do so. Could you please provide clear steps to reproduce it from a clean installation of Drupal and select or other?

tlyngej’s picture

Sure.

On a site where you only have Drupal installed, using the "Standard" profile, and the "Select or Other" module:

  1. Go to admin/structure/types/manage/page/fields and add a new "List (text)" field to the page content type where you set the allowed values to be test|TEST
  2. On the same content type, add another "List (text)" where you set the allowed values to be test2|TEST2
  3. Go to admin/structure/types/manage/page/form-display and set the first field you created widget to be "Select or Other"
  4. Go to node/add/page and try to select anything, but "- None -" in both or one of the select boxes and watch it fail submitting.
  5. Got to admin/structure/types/manage/page/form-display and select "Select list" instead of the "Select or Other" widget on the first field you created
  6. Go uninstall "Select or Other"
  7. Go back to node/add/page and submit the form again, with a value selected in the select boxes, and it will submit

Side-note: If you set the key and the value to be the same, in allowed values, the form will submit.

legolasbo’s picture

Status: Postponed (maintainer needs more info) » Needs review
Issue tags: +DevDaysMilan
FileSize
709 bytes

The attached patch fixes the issue at hand. However I haven't been able to test if it doesn't introduce any problems with the addition of new values to select or other enabled fields. Please test the patch thoroughly if you can, so it can be committed swiftly.

tlyngej’s picture

I'll give it a spin.

tlyngej’s picture

Status: Needs review » Reviewed & tested by the community

I'm happy with it :-)

Tested that both the field, using the "Select or other" widget, and other fields are working, when this patch is applied to the module.

  • legolasbo committed 41d013f on 8.x-1.x
    Issue #2694249 by legolasbo, tlyngej: "The value you selected is not a...
legolasbo’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x-1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

gaurishankar’s picture

patch #7 working for me.
Thanks

frederickjh’s picture

For anyone else finding this is a Select or other bug. It was fixed this issue #2694249: "The value you selected is not a valid choice" error is thrown when using integer lists . It is in the dev version and the patch in this issue applies cleanly to the current version 8.x-1.0-alpha2 of Select or other.

kiliweb’s picture

Patch #7 is working for me too.
If you are using "8.x-1.0-alpha2", consider switching to the "8.x-1.x-dev"

Thank you.

superlolo95’s picture

I am using the dev version with workflow module.
Unforutnatelly this is not working.
What am I missing ?
thanks

gintass’s picture

In the alpha3 release notes this issue has been marked as fixed. It hasn't. I'm using this version 8.x-1.0-alpha3 on Drupal core 8.7.1 and the list fields with integer values still give me this error when I try to save the node - "The value you selected is not a valid choice"

Kris77’s picture

Same issue too...