I'm seeing the Javascript events on the CCK content type form - but I can't seem to see where to enter the Javascript code to execute?
I was hoping to use it to set a textfield to a default value when a value is selected from a pulldown before - but I can't seem to get it - any helps/hints gratefully received.
Comments
Comment #1
kenorb commentedHave you tried to define hook_ajax_trigger?
See example: http://drupal.org/node/498672
You need to return javascript code which should be executed.
Or you can go to Actions and create new 'Execute Javascript' action. And on triggers page assign this action to specified trigger.
Comment #2
csc4 commentedMy original question was triggered by not really understanding where to put the code from the example and seeing
in the code which made me think I was supposed to enter code in this form - but I couldn't find the form... I understand now - that's an action form.
I've tried to execute the example but I'm confused - I created a field_foo
I assume the first foo
Is the name of the custom module?
and the second foo
is actually the CCK field name?
Or are they both the CCK field name? and I don't see any javascript code that should be executed being returned in the example? I thought that was what ticking the box on the node type was going to do?
Comment #3
kenorb commentedYes, foo is the name of your custom module.
In hook_ajax_trigger you should return JavaScript or jQuery code which will be executed for web browser on client side.
Line:
is the value of field from current form (field_foo is the name of existing field in the form).
Action way:
1. Create an action on Action Page.
2. Edit any of field and activate javascript event (onchange or other action).
3. Assign this action to that event on Trigger Page.
hook_ajax_trigger way:
1. Edit any of field and activate javascript event (onchange or other action).
Javascript should be executed when you change value of that field (with 500ms delay).
Comment #4
kenorb commentedComment #5
csc4 commentedSorry - your help was really useful and I got it to work for foo - meant to say so!
Didn't manage to get it to work for fields in a multigroup, still trying!
A great module though.
Comment #6
kenorb commentedProbably you have to use correct path for fields in multigroup.
Try to dump the current $form, i.e. via watchdog() to the log system, or the the file and check which object you can use it (because it will be much more difficult to debug it via AJAX).
Comment #7
areafix commented> Action way:
> 1. Create an action on Action Page.
Hm.. Sorry, but what is "Action Page" and were is it?
Comment #8
kenorb commentedWhen you activate Action core module there will be additional menu item in Administer: Actions
There you can choose and create new Drupal actions.
Comment #9
areafix commented> When you activate Action core module...
I can't find "Action" module in Drupal's core module list. May be you mean "Trigger"?
Comment #10
areafix commentedkenorb,
I find "Actions" at Adminitration / Settings / Actions, it already active when Drupal is installed ;)
I make sample "Execute Javascript" action with simple "document.write('Hello, world!');" and can't find any avalible action for admin/build/trigger/ajax_trigger. Can you provide any example with simple working code for "action metod"?
Comment #11
kenorb commentedThen this newly created action you need to assign to AJAX Trigger (you will find it in Triggers).
If you don't have anything in Trigger, you need to activate at least one event in field settings.
Go to any field in content type, configure it and tick the checkbox with some JS action.
Comment #12
areafix commentedI have performed all these steps, of course.
http://areafix.users.ru/img/ajax_trigger/actions.png
http://areafix.users.ru/img/ajax_trigger/inside.png
http://areafix.users.ru/img/ajax_trigger/ajax_triggers.png
Something wrong with my hands or in modile. D6.14, cck 3.0-dev.
Comment #13
kenorb commentedDo you have CCK module?
1. Go to Content Type (admin/content/types)
2. Choose one of the content type where you want to make an action and click on 'manage fields' (CCK module required).
3. Then choose some field which you want to assign some JS action and click 'Configure'
Could be checkbox, textfield, dropdown, anything.
4. You should have page similar to this: admin/content/node-type/your_content_type/fields/field_your_field
You will see additional checkboxes in 'Javascript Event:' section.
Select few of them.
5. Go back to your AJAX Trigger section (where you had empty), this field should appear there with specified action.
6. Assign your created action.
7. To test it, go to the form where you have this specified field and change it (if you selected event onchange).
I'm not sure if document.write() will work, but try alert(1)
Comment #14
areafix commentedkenorb, yes, i have cck installed, as I wrote in #12 comment. cck-3.0, may be this is problem, but I tried to play with ajax trigger before upgrading cck to 3th version with same result.
All from 1) to 4) I maked, as you can see at http://areafix.users.ru/img/ajax_trigger/ajax_triggers.png, I have two configured in cck fields events for field_author and field_position.
Yesterday I made all via computed field, it is not so good, because change performed at node save and not interactive. At the end of October I’ll move site from development to production and can downgrade cck to 2nd version at development version of the site to test ajax trigger with cck-2 in my environment.
And last. I find 'Javascript Event:' section not only in admin/content/node-type/story/fields/field_position, but in 'Edit basic information' too. This part not working, any changes in this place are preserved with no results as new ajax triggers at triggers page.
Comment #15
kenorb commentedCan you send me website where it doesn't work (on prv), I'll play around why it doesn't work.
Comment #16
carligraph commentedi also had no success to trigger an ajax-trigger action with an onchange-event. i followed the steps described by you at #13 and used alert('HELLO'); to test it - nothing happens..
what must be in the source code of the relevant cck node-edit-form ?
i also activated ahah forms - maybe is that the problem ?
the following code is visible in the source:
and there are many more fields (all available cck fields for that content type!)
field_screeningselect schould be the triggered field. it seems that there will be triggered one field called field_tickets, but there does'nt exist one in that node-type, but the node type is called 'tickets' itself!
maybe this helps to find a solution, thanx for your help!
edit:
was my mistake, it's there now. but anyhow it doesnt do anything if changing the select :(
this may be that: node/117346#comment-198761
Comment #17
kansaj commentedReally nice module,
but it is really working? I have tried it without any success to have some result. I followed all of the steps, described here but nothing happen.
cheers
Comment #18
kenorb commentedkansaj: what have you tried? which step doesn't work for you? do you have actions listed on trigger page?
Comment #19
kansaj commentedHi with the action listed on the trigger page is ok after clearing of the cache. The problem is that I'm not able to trigger an ajax-trigger action with any of the events. Everything is on place as explained in #13., but being in the node-edit form the supposed to happen events do not happen.
Here is the example (both fields are available)
JavaScript Code:
Comment #20
joelbox-mondial-it commentedhi I tried with this version and your new tar. It is a great module which could unlock real dynamics in drupal!
but however i can't get it to work on a 6.15 release and current modules.
Do you have any idea on what i could do next? I inspected the code, but could not find any clue there.
kind regards Joel,
Comment #21
kenorb commentedCommited some improvements proposed by Paul Hruska.
http://drupal.org/cvs?commit=348994
Comment #22
kenorb commented#30 joel box:
if you get Permission Denied on admin/build/trigger/ajax_trigger and you have admin privileges, you have something broken in your Drupal installation.
Try to rebuild your permissions, make sure that you have permission 'administer ajax_trigger', etc.
If you don't have 'AJAX Trigger' tab on Trigger screen, you have to add at least one js event on CCK field settings form (e.g. admin/content/types/fields).
But if you have it, and you still don't see 'AJAX Trigger' tab, try to go directly to that path: admin/build/trigger/ajax_trigger
I don't know why it doesn't work, it's some kind of Drupal access bug probably, related to:
#324183: Better Access Control in Custom Triggers
Some related articles:
http://drupal.org/node/375833
http://zzolo.org/thoughts/drupal-actions-and-triggers
Comment #23
kenorb commentedUPDATE:
Yes, it's related to permission issue: #324183: Better Access Control in Custom Triggers
You can't see the tab, because probably you using admin_role and you are not logged in as the real admin.
Fixed here:
http://drupal.org/cvs?commit=349042
Comment #24
joelbox-mondial-it commentedhi kenorb, indeed logged into the uid 1, and I can get to the admin/build/trigger/ajax_trigger via the url,
I updated next to your last version and it works fine. Thanks for the great work.
Perhaps some javascript examples would be welcome.
thx and kr. Joel
Comment #25
kenorb commentedAt the moment there is only example of hook_ajax_trigger:
http://drupal.org/node/498672
Comment #27
zualas commentedIs comment #13 solved somehow? I have exactly the same problem:
I define a Javascript action in Actions
I enable a Javascript event for a CCK field
I check the triggers - the field event is there, but I cannot assign any action to it. I can only see the message:
"No available actions for this trigger."
No matter what action I specify, it is not available for Ajax triggers...
Thanks!
Comment #28
kenorb commented#27 zualas - go to any CCK field settings page and activate any JavaScript event in checkboxes (#13 - step. 4.)
Comment #29
zualas commentedThat's my point, it does not help! See my screenshots, where I do the following:
1) Activate an event for CCK field
2) Create a Javascript action
3) Try to bind an action to a trigger, but there are no actions to select from...
Thought that some modules were interfering, so I did a clean install with only Ajax trigger, trigger and CCK modules enabled. No difference, can't select any actions.
Btw, I'm on Drupal 6.16 with CCK 2.x dev.
thanks
Comment #30
zualas commentedsorry, the file
Comment #31
kenorb commentedThanks for reporting this.
Fixed.
http://drupal.org/cvs?commit=364000
Comment #32
zualas commentedI tested it and it works fine. Thank you for the fix!
Comment #33
kenorb commented#5 #923178: Doesn't work with CCK fields in multigroup
Comment #34
ionmedia commentedi am logged in under uid=1 and i have no access to admin/build/trigger/ajax_trigger (access denied) but i have full access to admin/settings/ajax_trigger
so, i think it is not permissions trouble
if i just comment
i have access to admin/build/trigger/ajax_trigger , but triggers not working
fo tests we can just uncomment strings in
i have now 2 projects with ajax_trigger.
at first project i have no troubles with triggers and with access (all works fine without any issues)
on second i have this issues and triggers not working at all.
Comment #35
ionmedia commentedno way... with function ajax_trigger_menu_alter i can't see this tab on my second site
after removing this function and clearing menu cache i can see settings and add triggers, but they not working
same actions & triggers work fine on another installation (alert("ajax_trigger_ajax_trigger called");)
very, very strange issue and now i don't know how we can debug this module
at the final, i tried to install this module on 3rd site and there is i have no problems with calling trigger, but tab was hidden again
at the 4th site this module not working again (uncommented string with alert("ajax_trigger_ajax_trigger called"); have no effect on change field with js trigger settings).
in 2nd and 4th site we have installations of drupal not in www root folder (www.domain.com/path/to/drupal)
can this affect on work of this module ?
and more, at all installations button_field trigger works fine
Comment #36
ionmedia commented#972034: baseurl problem fix this part of issue
Comment #37
kaldimar commentedI never could manage to make any AJAX Trigger options appear under admin/build/trigger/node despite have been through #13 steps carefully. Using 6.x-1.0-beta1 on 6.20. Something is wrong but I don't know where.
BTW, if your module requires the core optional Trigger module to be enabled, you should include it in dependencies[], as well as CCK.
Comment #38
kenorb commentedClosed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.