By sisko on
Hey everyone,
I just found out something interesting about views. It seems it strips out any javascript you include via the "Rewrite the output of this field".
I included this code in the rewrite area => <a href='#' onclick="alert('test working!')"> [title] </a>
The output comes up with the field title fine but I clicked and nothing happened. Using firebug, I found the link did not have my javascript. The html output is as follows:
<a href="#"> Banner1 </a>
Very sime output as expected but my javascript is completely missing.
Can someone tell me why this happens and how I may find a way around ?
Comments
_
Not sure about why, but you should be able to work around it by theming the field, the view, or simply adding the js/jquery to the theme. I'd probably just do the latter.
hi!
where do you add the js/query to the theme? particularly in zen?
thanks
i just found this, which
i just found this, which might be usefull for others stumbling over this post:
http://drupal.org/node/352970
I would use the views custom
I would use the views custom field module:
http://drupal.org/project/views_customfield
set the input type to php and it won't try to clean it up.
Thank you
. . . much appreciated
and how would you insert such
and how would you insert such a link:
Create a new customfield
Create a new customfield (php) and enter:
That will print out all of the fields in your view and show you their PHP variable identities in the $data array. Find the field you want by searching through the output.
You'll see something like $data->field_my_field = my_field_value. That will let you know that your field is referred to as $data->field_my_field.
Then you can write a php script like this:
In my situation I need to use
In my situation I need to use the values of other fields in my jquery.
I tried this in a PHP field:
But its returning the wrong date for some reason. It is a day ahead and it displays no time. Even when I only print out the full date. What could be wrong here? Thanks!
Bear with me ...
as I may not actually end up helping - here it goes.
It's been a while since I posted the original message so I don't even remember the specifics of the original problem.
But I think I eventually resolved the problem by NOT putting my jquery code in views but instead I wrote a custome module.
The module only works when I arrive one a specific page.
Then it reads data from the page into a javascript value and begins to do whatever needs to be done.
In my experience, the javascript into views fields doesn't seem to work and it's worth exploring alternatives.
I really hope I have helped.
Cotent don't showing correctly
I have built a view using view module, where I used so table from the fields of the registered user of the wepsite to see different users and their contents as a list. But the list does not show all the users but only two. I don't know what is the problem.
Then it reads data from the
You have any detail on how you did this?
Henrik Akselsen | frontkom | Twitter: @FrontHenrik
Views php module for Drupal 7 is a work around
As someone eluded to by mentioning views customfield module, you can work around this issue by installing the views PHP module ( https://www.drupal.org/project/views_php ) which allows both php and javascript in the new "Global: PHP" view field it creates. The Views Php module does not rely on the php module to be turned on and allows processing of both php and javascript code. Messy, but it works.
need drupal 8 version
Need a drupal 8 version of this to work.... Taking a look here http://enzolutions.com/articles/2015/10/11/how-to-include-php-code-in-dr...
Also here is D7 info related: http://drupal.stackexchange.com/questions/65672/views-field-rewrite-oncl...
https://stackoverflow.com/a
https://stackoverflow.com/a/43131240/227926