I love being able to rewrite the output of various fields in Views; however, I've run into a problem. Apparently, you can't include event handlers like OnMouseOver, OnMouseOut, etc. in the rewrite output box (at least if you want them to show up when you visit a page with that view).
Here's my situation. I have a client who wants a thumbnail image to pop up when a certain title is moused over; normally, this takes just a simple Javascript and an event handler--in this case, onMouseOver. However, because this title happens to appear in a view, I figured I would need to rewrite the output to add the event handler.
However, no matter what tags I use, whenever I try to add an event handler (onmouseover="jsfunction(stuff)") to tags in the rewrite output box, they are removed from the HTML when I visit the page with the view. Is there not any way to include event handlers in the rewritten output? If not, does anyone know of a workaround?
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 686942-rewrite_filters.patch | 2.68 KB | ben kuper |
Comments
Comment #1
rbenhase commentedTo clarify, the tags I create when I rewrite the output are not removed from the HTML on the page with the view; it's just the event handlers that are missing.
So,
<a href="#" onmouseover="jsfunction(something)">becomes just
<a href="#">I really would like my JavaScript function to be called on mouseover, but without being able to use an event handler within the Views field content, I'm out of luck.
Comment #2
merlinofchaos commentedjavascript embedded in tags is considered bad form in Drupal, insecure and unmaintainable. Your .js file should attach javascript via selectors and jQuery handlers (for example, $('#id).bind('mouseover', function () { ... }).
Comment #3
rbenhase commentedThanks for the advice. I'm relatively new to Drupal and jQuery, too. I understand why it's best to do things as you explained. Unfortunately, when I add something like $('#id).bind('mouseover', function () { ... }). to my .js file, it doesn't seem to work; nothing happens on mouseover and there's no evidence that the Javascript is even trying to do anything here. Other functions in the Javascript work fine. Am I missing something?
Comment #4
alberto56 commentedI'm having a similar problem with "Rewrite output of this field".
I'm trying to rewrite a "price" field as a PayPal button (a form). However, Views deletes form tags entirely when you "Rewrite this field as...". Thus, rewriting [title] as
produces
I think this is a problem because the help text says you can enter html, so presumably users will be surprised that they can enter html, but not any html -- It is not immediately clear what filtering Views uses for these rewritten fields.
As mentioned above, "javascript embedded in tags is considered bad form in Drupal". True, but it is not Views's role to enforce that standard. Rather, as when users create block, nodes, or indeed even headers and footers in Views themselves, they may select any input format to which they have access.
Thanks,
Albert.
Comment #5
mikemccaffreyI am having the same trouble rewriting a field to be an embedded youtube video. The object, embed, and param tags are being ommitted from the output.
Switching this to a bug report, since the help text does say "You may include HTML".
Comment #6
dawehnerThat's the design here. It uses filter_xss_admin to ensure that the output is secure.
If you need tags like object/embed you better use theming of a single field.
Comment #7
alberto56 commentedIf this feature will make it in, perhaps 7.x-3.x is the appropriate branch.
Comment #8
dawehnerNo 7.x-3.x doesn't get new features only.
Comment #9
alberto56 commented@dereine thanks. Just to confirm: new features go into 6.x-3.x, then are carried over to 7.x-3.x, right?
Comment #10
bojanz commented@alberto56
Correct. 6.x-3.x and 7.x-3.x are kept in sync.
Comment #11
dawehnerWhat is the use case for forms if you can't have fapi, because the form isn't dynamic.
Alternative you can extend views to embed a full form, there is no reason to hack this into the rewrite output field.
Comment #12
alberto56 commented@dereine the form usecase is to add a form from an external source like PayPal (displaying a paypal button requires inserting form code generated by PayPal which doesn't go through the FAPI), but it is just an example. If a user has the permission to use the full HTML input format, it seems arbitrary to filter his or her "rewrite this field as..." content for security purposes.
Comment #13
ben kuper commentedI'm in the same case.
I created input format for automation of jquery tooltip, and it would be really convenient to just add [tooltip target="mytitle-id"]My content in tooltip[/tooltip] in the " rewrite output" text area.
I tried to modify the textarea in views_handler_field.inc to accept input formats, but when i save it, nothing is displayed and the textarea is blank on the next edit.
I understood the filter is first processed by the token module, then processed by filter_xss_admin. And i don't know what to do to send it to the chosen input format filter.
Comment #14
merlinofchaos commentedPerhaps views custom field will provide a field that can be run through an input filter?
Comment #15
ben kuper commentedYes that would be somthing like that but it's not ported to D7...
I'll see what would be the best solution and try to commit a patch when i found one...
Comment #16
ben kuper commentedOk, i managed to transform the "Rewrite output" textarea into a text_format textarea.
Merlinofchaos i think you're right. Even if i can do what i wanted to do with my modifications, i actually understood while i was doing it that what i wanted is a field with both custom filter formats and tokens functionnality.
Unfortunately, Views Custom Field's D7 successor Views PHP doesn't seem to implements any of these.
I'll post a patch here when i come with something clean enough.
Comment #17
ben kuper commentedHere is the patch.
Please note that :
- this patch add some D7-specific syntax & functionnalities (text_format and #states), so D6 users might want to take a look at it and backport it to D6 version.
- The text_format field & #states don't react well, the [temporary] fix for this is simple and is discussed here : #997826: #states doesn't work correctly with type text_format
Comment #18
dagmarIf this value is not defined in option_definition, never will be saved.
Patches should remove lines, not comment them.
Even for D7, this is not respecting the Coding Standards
Trailing spaces
I'm not sure if this 'idea' should be considered at all. Include a text format at this level is really bad, a lot of fields don't need text formats and should be managed by other custom fields as @merlinofchaos said in #14
Powered by Dreditor.
Comment #19
ben kuper commentedYes thanks for the corrections.
Indeed, i think the the D7 port Views PHP of Custom Field module should keep the Custom Input format field integration.
Comment #20
alberto56 commentedNot sure I agree with you completely: using filter_xss_admin() seems a bit arbitrary to me; moreover, entering text for output to the screen seems to be exactly what input formats are designed for.
However, security implications can be imagined for this approach, but the same goes for "filter_xss_admin()". Why should a user with access only to Filtered HTML have access to create output via filter_xss_admin() in views? Conversely, why should a user with access to Full HTML be limited to filter_xss_admin() in views?
Custom fields seems like a good idea though, thanks for pointing me in that direction.
Cheers!
Albert
Comment #21
merlinofchaos commentedI agree with dagmar. Attempting to add the filter system to the rewrite is very risky and will almost certainly break a lot of sites.
Views custom field is the answer. If it's not yet ported to D7, then I recommend you focus efforts on helping port.