1

My case is simple: When user switches tabs, I want to dynamically fill empty fields in the tab he entered, calculating them from the tab he went from. Like suggesting city by zip code, or address by company name if I have it in database.

Problem is - I can do it on button click or on field's blur, but I'd prefer it to happen on vertical tab switch. Items with vertical_tabs type simply does not have #ajax property. Is there any neat way around it?

#states seemed a solution, but it seems they only support static value set, like:

':input[name="foo"]' => array('value' => 'bar'),
1

#states attributes cannot use to invoke AJAX. See drupal_process_states

With your question, i think the solution is write an javascript file and #attached it to the form you need.

You can bind a click event to .vertical-tab-button element (better) or orverride Drupal.verticalTab.prototype.focus function (not recommend).

  • Could you elaborate why don't you recommend using Drupal.verticalTab.focus? – Mołot Jun 19 '13 at 10:22
  • bad thing about .vertical-tab-button is - it does not contain any kind of id I could use. Any idea how to reliably recognize which one was clicked? – Mołot Jun 19 '13 at 15:48
  • Because Drupal.verticalTab ship from core. We only change core behaviors when we haven't any other solution. When an .vertical-tab-button click, it'll have class selected – Sang Le Thanh Jun 19 '13 at 16:04
0

I would recommend to override Drupal.verticalTab.prototype.focus though @Sang Le Thanh said not to do so.

You can apply the default behaviour with your custom logic which will not break any Drupal core function.

var defaultFocus = Drupal.verticalTab.prototype.focus;
Drupal.verticalTab.prototype.focus = function() {
    // enter your code
    defaultFocus.apply(this);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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