Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/rails.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,14 @@
form.find('input[data-disable-with]').each(function() {
var input = $(this);
input.data('ujs:enable-with', input.val())
.val(input.attr('data-disable-with'))
.attr('disabled', 'disabled');
.val(input.attr('data-disable-with'));
});
}

function enableFormElements(form) {
form.find('input[data-disable-with]').each(function() {
var input = $(this);
input.val(input.data('ujs:enable-with')).removeAttr('disabled');
input.val(input.data('ujs:enable-with'));
});
}

Expand Down Expand Up @@ -117,10 +116,17 @@

$('form').live('submit.rails', function(e) {
var form = $(this), remote = form.attr('data-remote') != undefined;
if (form.data('submitted')) {
return false;
} else {
form.data('submitted', true);
}
if (!allowAction(form)) return false;

// skip other logic when required values are missing
if (requiredValuesMissing(form)) return !remote;
if (form.attr('data-validate') != undefined) {
if (requiredValuesMissing(form)) return !remote;
}

if (remote) {
handleRemote(form);
Expand All @@ -130,14 +136,24 @@
}
});

// Implement this for ie, because if you press enter on a submit it has a weird execution order
if ($.browser.msie) {
$('input').live('keydown', function(e){
if (e.keyCode == 13) {
$(this).parents('form').submit();
return false;
}
});
}

$('form input[type=submit], form button[type=submit], form button:not([type])').live('click.rails', function() {
var button = $(this);
if (!allowAction(button)) return false;
// register the pressed submit button
var name = button.attr('name'), data = name ? {name:name, value:button.val()} : null;
button.closest('form').data('ujs:submit-button', data);
});

$('form').live('ajax:beforeSend.rails', function(event) {
if (this == event.target) disableFormElements($(this));
});
Expand Down