6

I'm working with standard admin form, which has 'add_more' button for one of fields.
example dialog with «add more» button
My task is to move some fields to jQuery UI Dialog just for usability. When dialog was closed I manually append it's content to form so It sends normally.
The problem appears when some core ajax is sending while some form parts are in the dialog (i.e. outside of form tag because jQuery UI Dialog appears in the bottom of body). The 'add_more' button as example. When I click on it, the form serializes for AJAX without some inputs in the dialog.
Оh..
The jQuery Form Plugin (which used by Drupal) has option beforeSerialize. I think it can help me but I don't know how I can extend Drupal.ajax.options to set something custom.

If you can recommend other ways to solve my problem or give some links to documentation about Drupal JavaScript, I will be very happy :)

Thanks.

2 Answers 2

9

Thank you, @yvan, for answer. Links you added are good.
But there are better documentation in source code comments. If you want to understand how it works you should look through files includes/ajax.inc and misc/ajax.js.
My problem was solved like this:

(function($) {
Drupal.behaviors.MyModule = {
    attach: function (context, settings) {

        // Overwrite beforeSubmit
        Drupal.ajax['some_element'].options.beforeSubmit = function (form_values, element, options) {
            // ... Some staff added to form_values
            // return false; // to prevent AJAX call if needed.
        }
        //Or you can overwrite beforeSubmit
        Drupal.ajax['some_element'].options.beforeSerialize = function (element, options) {

            // ... Some staff added to options.data
            // Also call parent function
            Drupal.ajax.prototype.beforeSerialize(element, options);
        }

                    //...

These functions are calling in jQuery Form Plugin.

0

It's a little bit sad, but the JavaScript Documentation for Drupal 7 is really poor but still better than Drupal 6 :)

Well, I understand your problem and I haven't found a solution, I just can send you to some interesting pages that can help you.

First, about Ajax Forms in Drupal 7 who send you also to Ajax Framework and finally look into Example Ajax Module, maybe you'll find something that can help you.

2
  • Yes, these pages are good for understanding concepts of AJAX Forms in Drupal. But I wanted something more :)
    – kalabro
    Commented Aug 24, 2011 at 16:52
  • 1
    I fount it in the Drupal documentation, hook_ajax_render_alter maybe it's can help you. One of the commands is "setting".
    – yvan
    Commented Aug 25, 2011 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.