Posted by csc4 on August 30, 2009 at 5:06pm
10 followers
| Project: | AJAX Trigger |
| Version: | 6.x-1.x-dev |
| Component: | User interface |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
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
#1
Have 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.
#2
My original question was triggered by not really understanding where to put the code from the example and seeing
function ajax_trigger_action_form($context) {$form = array();
$form['code'] = array(
'#type' => 'textarea',
'#title' => t('JavaScript Code'),
'#default_value' => isset($context['code']) ? $context['code'] : '',
'#description' => t('Type here JavaScript/jQuery code.')
);
return $form;
}
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
function foo_ajax_trigger($form, $field, $op) {Is the name of the custom module?
and the second foo
$price = (int)$form['field_foo'][0]['value']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?
#3
Yes, 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:
<?php$price = (int)$form['field_foo'][0]['value'];
?>
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).
#4
#5
Sorry - 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.
#6
Probably 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).
#7
> Action way:
> 1. Create an action on Action Page.
Hm.. Sorry, but what is "Action Page" and were is it?
#8
When you activate Action core module there will be additional menu item in Administer: Actions
There you can choose and create new Drupal actions.
#9
> When you activate Action core module...
I can't find "Action" module in Drupal's core module list. May be you mean "Trigger"?
#10
kenorb,
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"?
#11
Then 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.
#12
I 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.
#13
Do 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)
#14
kenorb, 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.
#15
Can you send me website where it doesn't work (on prv), I'll play around why it doesn't work.
#16
i 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:
<input type="hidden" name="ajax_trigger" id="ajax_trigger_timeout" value="500" /><input type="hidden" name="ajax_trigger" id="ajax_trigger" value="{"field_tickets":{"javascript_event":{"change":"change"}},"field_ticketssold":{"javascript_event":null},"field_screeningselect":{"javascript_event":null},"field_ .... }" />
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:
"field_screening":{"javascript_event":{"change":"change"}}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
#17
Really 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
#18
kansaj: what have you tried? which step doesn't work for you? do you have actions listed on trigger page?
#19
Hi 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)
<input type="hidden" name="ajax_trigger" id="ajax_trigger" value="{"field_newcars":{"javascript_event":{"change":"change","keypress":"keypress"}},"field_formercars":{"javascript_event":{"change":"change"}},"
field_agree":{"javascript_event":null}}" />
<input type="hidden" name="ajax_trigger" id="ajax_trigger_timeout" value="500" />
JavaScript Code:
alert('HELLO');#20
hi 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,
#21
Commited some improvements proposed by Paul Hruska.
http://drupal.org/cvs?commit=348994
#22
#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
#23
UPDATE:
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
#24
hi 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
#25
At the moment there is only example of hook_ajax_trigger:
http://drupal.org/node/498672
#26
Automatically closed -- issue fixed for 2 weeks with no activity.
#27
Is 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!
#28
#27 zualas - go to any CCK field settings page and activate any JavaScript event in checkboxes (#13 - step. 4.)
#29
That'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
#30
sorry, the file
#31
Thanks for reporting this.
Fixed.
http://drupal.org/cvs?commit=364000
#32
I tested it and it works fine. Thank you for the fix!
#33
#5 #923178: Doesn't work with CCK fields in multigroup
#34
i 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
<?phpfunction ajax_trigger_menu_alter(&$items) {
$items['admin/build/trigger/ajax_trigger']['access arguments'] = array('administer ajax_trigger');
}
?>
i have access to admin/build/trigger/ajax_trigger , but triggers not working
fo tests we can just uncomment strings in
<?php
/**
* Implementation of hook_ajax_trigger().
*/
function ajax_trigger_ajax_trigger($form, $field, $op) {
//dpm(array('form' => $form, 'field' => $field, 'op' => $op));
//return 'alert("ajax_trigger_ajax_trigger called");';
?>
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.
#35
no 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
#36
#972034: baseurl problem fix this part of issue
#37
I 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.