I'm trying to have a Select dropdown list render values both allowed and not allowed. Example. I have a list of Ice Cream flavors (Chocolate, Vanilla, Strawberry), and I coded PHP validation scripts to throw a form_error when someone selects "Strawberry" to say, "Sorry, we don't serve Strawberry yet."

I've tried using jQuery to replace/add the options in the field list, but the validation for it gets ignored because the value/key Strawberry are in the list of Options for the form element. I have tried to remove the Strawberry value for the field, then use jQuery to render all options, but Drupal says the value chosen was illegal and I should contact the site administrator - so it knows I injected an unexpected value, which is neat but the message is not what I want users to see.

Comments

quicksketch’s picture

As you found, Drupal will not allow any injected value to be submitted, so you can't use jQuery to add items to the list. However, you can easily *remove* items from the list, or through JS errors when an item is selected. I understand the scenario you're describing, but I'm not sure what you're trying to accomplish. What's expected to happen when a user selects a value that isn't valid (and why show them at all if you don't support them?).

quicksketch’s picture

Status: Active » Closed (fixed)

Closing after lack of activity.

ManinZ’s picture

Title: Select list containing options that are both valid and invalid » true
Component: Miscellaneous » Code
Assigned: Unassigned » ManinZ
Category: support » feature

That article is so factual! Well, that scenario is very natural nowadays. Why don’t you try to emanate the strategies being applied by the Carvel chain? Carvel, the ice cream chain, is jumping on the giveaway promo bandwagon, giving out a free Iceberg drink at all Carvel locations. The chain is located mostly on the East Coast, as almost 200 of their 500 locations are located in New York State alone. The giveaway is for the company's 75th anniversary. Tom Carvel started the company with a cash advance in the 1930s. He built a franchise of frozen custard stores, ushering in the era of soft serve. The company became renowned for its ice cream cakes, lauded and parodied in pop culture for decades. You won't need installment loans for an iceberg from Carvel.