Merge "Disable submit action button until any of list item is selected"
This commit is contained in:
commit
a6c39e5ba6
@ -9,6 +9,31 @@ horizon.addInitFunction(function () {
|
||||
return true;
|
||||
});
|
||||
|
||||
// Disable form button if checkbox are not checked
|
||||
$("form").each(function (i) {
|
||||
var checkboxes = $(this).find(":checkbox")
|
||||
if(checkboxes.length == 0) {
|
||||
// Do nothing if no checkboxes in this form
|
||||
return;
|
||||
}
|
||||
if(checkboxes.filter(":checked").length == 0) {
|
||||
$(this).find(".table_actions button.btn-danger").addClass("disabled");
|
||||
}
|
||||
});
|
||||
|
||||
$("form :checkbox").on("click", function (evt) {
|
||||
var $form = $(this).closest("form");
|
||||
var any_checked = $form.find(":checkbox").is(":checked");
|
||||
|
||||
// Enable the button if any checkbox is checked,
|
||||
// Disable if all checkbox is cleared
|
||||
if(any_checked) {
|
||||
$form.find(".table_actions button.btn-danger").removeClass("disabled");
|
||||
}else {
|
||||
$form.find(".table_actions button.btn-danger").addClass("disabled");
|
||||
}
|
||||
});
|
||||
|
||||
// Confirmation on deletion of items.
|
||||
// TODO (tres): These need to be localizable or to just plain go away in favor
|
||||
// of modals.
|
||||
|
@ -58,6 +58,9 @@ var Horizon = function() {
|
||||
horizon.datatables.confirm = function (action) {
|
||||
var $action = $(action),
|
||||
action_string, title, body, modal, form;
|
||||
if($action.hasClass("disabled")) {
|
||||
return;
|
||||
}
|
||||
action_string = $action.text();
|
||||
title = "Confirm " + action_string;
|
||||
body = "Please confirm your selection. This action cannot be undone.";
|
||||
|
@ -25,6 +25,22 @@ horizon.addInitFunction(function() {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
var $form = $('.modal:last').find('form');
|
||||
if($form) {
|
||||
var checkboxes = $form.find(":checkbox")
|
||||
if(checkboxes.length != 0 && checkboxes.filter(":checked").length == 0) {
|
||||
$form.find(".table_actions button.btn-danger").addClass("disabled");
|
||||
}
|
||||
$form.find(":checkbox").on("click", function (evt) {
|
||||
var any_checked = $form.find(":checkbox").is(":checked");
|
||||
if(any_checked) {
|
||||
$form.find(".table_actions button.btn-danger").removeClass("disabled");
|
||||
}else {
|
||||
$form.find(".table_actions button.btn-danger").addClass("disabled");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO(tres): Find some better way to deal with grouped form fields.
|
||||
var volumeField = $("#id_volume");
|
||||
if(volumeField) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user