Skip to content

Commit

Permalink
Add form validation for share selected multiple times rockstor#2064
Browse files Browse the repository at this point in the history
Selecting the same share to be bound to multiple volumes of the
same container is not yet supported by Rockstor. Add a new
validation rule isDuplicate to detect such instances of a share
being selected as the option for more than one volume and return
a specific error message accordingly.
  • Loading branch information
FroggyFlox committed Jan 20, 2023
1 parent ac664dc commit 2a7b041
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/rockstor/storageadmin/static/storageadmin/js/views/rockons.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @licstart The following is the entire license notice for the
* JavaScript code in this page.
*
* Copyright (c) 2012-2013 RockStor, Inc. <http://rockstor.com>
* Copyright (c) 2012-2023 RockStor, Inc. <http://rockstor.com>
* This file is part of RockStor.
*
* RockStor is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -580,15 +580,36 @@ RockonShareChoice = RockstorWizardPage.extend({
}));
//form validation
this.volForm = this.$('#vol-select-form');

// Check for duplicate shares selected (one share selected multiple times)
$.validator.addMethod('isDuplicate', function(value, element) {
var selector = jQuery.validator.format("select[name!='{0}']", element.name);
var matches = [];
$(selector).each(function(index, item) {
if (value === $(item).val()) {
matches.push(item);
}
});
return matches.length === 0;
});

var rules = {};
var messages = {};
this.volumes.each(function(volume) {
rules[volume.id] = {
required: true
required: true,
isDuplicate: true
};
messages[volume.id] = {
required: "Required. Please read the tooltip and make your selection.",
isDuplicate: "This share is already selected for another volume. This isn't supported yet."
};
messages[volume.id] = 'Please read the tooltip and make the right selection';
});
this.validator = this.volForm.validate({
focusCleanup: false,
onclick: false,
onfocusout: false,
onkeyup: false,
rules: rules,
messages: messages
});
Expand Down

0 comments on commit 2a7b041

Please sign in to comment.