When I'm trying to use FAPI #states for submit button I'm getting an error:

Error: Syntax error, unrecognized expression: #

in browser's console.

So, I decided to debug Webform module and found that it removes id attribute for the button in pre-render function webform_pre_render_remove_id(), which is added in the webform_client_form(). But drupal_process_states() uses id attribute and it can not be empty. So, in the result we have an error, described above.

Comments

danchadwick’s picture

Priority: Major » Minor

@quicksketch - Why are the ids intentionally removed? Do we still need to do this?

@aprogs - if you are using hook_form_alter to add your #states, why not remove the pre-render that serves to remove the ids?

aprogs’s picture

Hi @DanChadwick,

I guess that there are weighty reasons for removing id attribute. So, I decided to ask about it here.

Thanks

quicksketch’s picture

@quicksketch - Why are the ids intentionally removed? Do we still need to do this?

The IDs are removed as part of an overall effort to reduce the use of IDs and increase the use of classes. Buttons in particular were a problem because if you had multiple forms on the page, the IDs of the submit buttons would keep changing out from under you, making any CSS that targeted them difficult to predict.

Restoring the IDs shouldn't cause any problems other than those we had before. It hadn't occurred to me that someone would want to use #states to hide/show the buttons themselves.

I'd suggest one of two approaches to fix this problem for your use-case:

1) In your form_alter(), remove the "webform_pre_render_remove_id" callback from the button #pre_render array.
2) Or perhaps just don't use #states and add your own JS.

We could also potentially put a fix in webform_pre_render_remove_id that checks if #states is set, and if so, leaves the IDs in place.

danchadwick’s picture

Version: 7.x-4.0-beta3 » 8.x-4.x-dev
Status: Active » Fixed
StatusFileSize
new1.32 KB

I liked quicksketch's third option: ids are only removed if there are no #states defined. Tested and applied to 7.x-4.x and 8.x.

  • Commit 96ef6ef on 7.x-4.x by DanChadwick:
    Issue #2279723 by DanChadwick: Fixed removing form IDs when #state is...
  • Commit 8c44d65 on 8.x-4.x by DanChadwick:
    Issue #2279723 by DanChadwick: Fixed removing form IDs when #state is...
aprogs’s picture

Thanks for paying attention to this issue.

Status: Fixed » Closed (fixed)

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

danchadwick’s picture

Version: 8.x-4.x-dev » 7.x-4.x-dev