With the FAPI, the multiselect element cannot be set to not require a value. I've tried setting the required attribute's value to FALSE, 0, etc. but the form cannot be submitted without a value unless the required="" attribute is completely removed from the HTML (with firebug).

I need this functionality for my advanced search form, which defaults to all when no value is selected.

Comments

attheshow’s picture

Priority: Major » Normal
ctotogo’s picture

Title: Required cannot be set to false » Required cannot be set to false - Temporary Workaround

Yeah, it's definitely having trouble. If I had more time tonight (crazy deadline tomorrow) I'd try to get to the bottom of it, but in the meantime since in each case it's not required in my app, I just added one line to the theme_multiselect function in multiselect.module just before the last line that returns the html as follows:

unset($element['#attributes']['required']);

which just removes it from the mix altogether. A kludge, granted, but will get you past it if you're not concerned about making any of your multiselects required at the moment.

Thanks so much to the author for all your hard work. It's a great module.

-- Carlos

Anonymous’s picture

Version: 7.x-1.x-dev » 7.x-1.8
Priority: Normal » Critical
attheshow’s picture

Priority: Critical » Normal
Anonymous’s picture

your kidding right?!

aron novak’s picture

Priority: Normal » Major

At least it's a major issue. @attheshow: if you have any hints on this, i'm happy to help with coding to fix this.

Depelck’s picture

This works in both cases:

if(!$element['#attributes']['required']) {
    unset($element['#attributes']['required']);
  }
mradcliffe’s picture

Status: Active » Needs review
StatusFileSize
new1.83 KB

This is a big issue for Firefox 10 and Chrome users using the new HTML 5 client-side validation for multiselect elements generated via FAPI.

The issue is that theme_multiselect() always sets the 'required' attribute in element_set_attributes(). I have attached a patch for review.

  • Apply: git am 0001-Patch-1216808-by-mradcliffe.-Fixes-required-attribut.patch
Steven Brown’s picture

Is there a way to use some type of alter function to accomplish this without patching the module? Just curious.

mradcliffe’s picture

Yes, you could implement theme_multiselect() in your custom theme.

max.parker’s picture

Issue summary: View changes
StatusFileSize
new1.25 KB

Re-rolling the patch provided by #8 against version 7.x-1.13 of the module.

mparker17’s picture

Status: Needs review » Postponed (maintainer needs more info)

multiselect-7.x-1.8 is no longer supported, because Drupal 7 is no longer supported.

Can you confirm if this is still an issue in multiselect-2.0.0-beta4?

I'm going to mark this issue as "Postponed (maintainer needs more info)"... but when you answer, please change it back to "Active". If there is no reply in ~6 months, then I will mark this issue as "Closed (outdated)". Thank you in advance for your understanding and patience as I try to keep this module's issue queue clear.