1

I'm working on a module where I have a form inside of a block, I'm using Ajax to submit the form, but I noticed that the form's inputs are disabled when sending a request with Ajax. Well in my case I want to keep using the form's input (keyup event) and displaying the result for each request.

// my current code
$form['combine'] = array(
    '#type'       => 'textfield',
    '#size'       => 255,
    '#maxlength'  => 128,
    '#attributes' => array('placeholder' => 'Search'),
    '#ajax'     => array(
        'callback'  => 'ajax_filter_callback',
        'effect'    => 'fade',
        'wrapper'   => 'result-content',
        'event'     => 'keyup',
    ),
);
2
  • 1
    Is there a reason to not use autocomplete functionality for this? I think that it will not disable the input element when using this method. Drupal Examples has this where you can see how they implement this: api.drupal.org/api/examples/… Jan 19, 2015 at 20:54
  • @burnsjeremy I don't know, maybe I'll use autocomplete, it's just a big query with many joins, it's a customized filter in fact, I used Views combined filter but it's a bit limited for my case, so I developed my own module, with a form in a block as a filter (the one that gets its inputs disabled), but I'll take the idea of autocomplete into consideration. thank you
    – teeyo
    Jan 19, 2015 at 22:57

1 Answer 1

1

That functionality is built-in so you'll need to monkey-patch Drupal.ajax.prototype.beforeSend (found in misc/ajax.js).

Copy the entire code, but remove/modify this line:

$(this.element).addClass('progress-disabled').attr('disabled', true);

So in your module or theme's JS file:

Drupal.ajax.prototype.beforeSend = function(xmlhttprequest, options) {
  // Place all code from the original function here, except the line above.
}

YMMV, you may unwittingly introduce unexpected behaviour by not waiting for each request to complete.

1
  • Thanks @clive, I know I may run into problems, but I guess it's not that elegant to disable the inputs, maybe wait behind the scene for the request to complete to make a new one, I don't know, I'll think about it, thanks again.
    – teeyo
    Jan 19, 2015 at 22:53

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.