Sha256: 508f33c09c570667f7ef98b7c57b74595f5a6d09a5500c83a4ebc76080891e9b

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

// Prevent enter key from submitting the form
$(document).on('keypress', 'form[data-behavior="trestle-form"] :input:not(textarea):not([type=submit])', function(e) {
  if (e.keyCode == 13) {
    e.preventDefault();
  }
});

Trestle.init(function(e, root) {
  var form = $(root).find('form[data-behavior="trestle-form"]');

  form
    .on('ajax:complete', function(e, xhr, status) {
      // Find the parent context and replace content
      var context = $(this).closest('[data-context]');
      context.html(xhr.responseText);

      // Initialize replaced elements within the context
      $(Trestle).trigger('init', context);

      // Focus the correct tab
      Trestle.focusActiveTab();
    })
    .on('ajax:success', function(e, data, status, xhr) {
      var context = $(this).closest('[data-context]');
      var location = xhr.getResponseHeader("X-Trestle-Location");

      if (location) {
        // Update the URL in the browser and context
        history.replaceState({}, "", location);
        context.data('context', location);
      }

      // Refresh the main context
      if (!context.hasClass('app-main')) {
        Trestle.refreshMainContext();
      }
    });

  // Loading indicator
  form.find(':submit').click(function() {
    var button = $(this);

    // Delay to ensure form is still submitted
    setTimeout(function() {
      button.prop('disabled', true).addClass('loading');
    }, 1);
  });
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trestle-0.8.6 app/assets/javascripts/trestle/components/_form.js