I would love the ability to use attribute selectors, eg for wildcard searches. A use case would be for Views Exposed Forms - each view/display gets a unique form id and could be matched with the following css partial attribute selector (the ^ means "starts with")
[id^=views-exposed-form-]
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | compact_forms-add_selector-875328-13.patch | 4.45 KB | nuez |
| #13 | compact_forms-add_selector-875328-11.patch | 4.45 KB | nuez |
| #9 | compact_forms-add_selector-875328-9.patch | 4.58 KB | nuez |
| #7 | compact_forms-add_selector-875328-7.patch | 4.52 KB | nuez |
| #4 | compact_forms-add_wildcard-875328-4.patch | 3.09 KB | nuez |
Comments
Comment #1
marcvangendYes, this would be great to have. Another syntax (a little friendlier to less technical users) would be to use wildcards like we do in block configuration:
views-exposed-form-*
Comment #2
yannickooThat would be possible with a jQuery selector:
[class^="views-exposed-form-"].Comment #3
marcvangendFYI: Currently, the module has a smart way of deciding (during a hook_form_alter) if the compact forms javascript needs to be added to the page. It does so by comparing the form_id to the module settings. If the module would allow jQuery selectors to be entered (as in #2), that would probably mean that it's no longer possible to figure out if the javascript needs to be added, so it should be added on every page.
Comment #4
nuezI´ve created a patch that adds the possiblity to select forms with an CSS ID wildcard. Please review.
Comment #5
yannickooHey Nuez, please use spaces instead of tabs :)
Tabs! Use spaces instead.
Tabs again
I think it would be better to allow every kind of selector like it is allowed in jQuery.
Comment #6
nuezHi yannickoo,
Thanks for the hint, i´ve generated the patch with git on ubuntu, so it´s the default behaviour, I think. Although I did manually remove some trailing whitespaces. Can you give me some more information about why spaces instead of tabs and how to change this in GIT? Maybe some links?
About the patch:
A standard Drupal form has no specific selectors apart from the ID. If you repeat that one form several times in the same page, Drupal will give each form a different ID (e.g. user-login--1, user-login--2 etc). That was the reason to add this. But using jqueyr selectors do make more sense and is probably easier to make. give me a second to redo the patch...
Comment #7
nuezNew patch...
Not sure whether the wildcard or jquery selector is the best option: The module matches the selector against the form properties. So the ID is matched against $form['id'] and the class against $form['attributes']['class']. To allow all the jquery selectors (with one or more elements) would mean a complete rewrite of the module.
This patch makes selecting by classes (added to the $form['attributes'] and Ids possible. I leave it to the module admins to decide which one is the best option.
Comment #8
yannickooThank you for taking time again and working on the patch :) Just reviewed it and found some coding standards issues. Please take a look at the coding standards. You can change the indentation style in your editor and coding standards say that you should use two spaces instead of a tab.
Oh, strange character here.
Do we really have to join that? We can also pass the whole selectors string.
Coding standards says that you have to uppercase booleans like TRUE and FALSE.
Coding standards says that you have to put a space after an if or foreach.
Why there are brackets around substr?
A missing space before the 1.
Uppercase the boolean.
Uppercase the boolean.
if ($apply)is enough.Comment #9
nuezThanks for the feedback, really appreciate it.
All the issues you´ve mentionted have been fixed. The jquery selector issue: haven´t changed that, because that´s the way it was done originally: the selectors are passed as a javascript array, they need to be joined into a string.
Since it was done like this in the original module, I changed it as little as possible,
Adding the patch once again,
Comment #10
yannickooSorry but there are minor things...
Why did you change this line?
Please use single quotes instead of double quotes, forgot that.
Why do you check for
$form['#id']?Please use single quotes instead of double quotes, forgot that.
Comment #11
yannickooWarning: substr() expects parameter 2 to be long, array given in compact_forms_pre_render() (line 82 of compact_forms.moduleAlso forgot to mention that I get a message because of
$form_id = substr($selector_value, array('-' => '_'));. You meanstr_replaceinstead ofsubstrright?Comment #12
nuezAllright:) thanks for the feedback again,
about #11: in the original code de strtr was used, don´t know why I changed that, but changed it into str_replace now. Patch looks clean now,
Comment #13
nuezthe patch
Comment #14
nuezAnd another small fix,
Comment #15
esmilia commentedI used patch #13 but i dont know how it works. What shall i add to the textarea of compact forms to use it for all webform-client-form ?
Comment #16
yannickooYou can use Compact Forms for all Webforms with just adding
.webform-client-forminto the textarea :)Comment #17
calebyoder commentedHmm.. This patch didn't apply right for me. :(
It says:
This feature is something that I would like! I'm having issues with a Views exposed form in a block. The problem occurs when I place the block into the mmenu (mobile menu) and they both have the same ID.