diff --git a/emhttp/plugins/dynamix.vm.manager/VMSettings.page b/emhttp/plugins/dynamix.vm.manager/VMSettings.page index fa80e80ed..5832f35f7 100644 --- a/emhttp/plugins/dynamix.vm.manager/VMSettings.page +++ b/emhttp/plugins/dynamix.vm.manager/VMSettings.page @@ -119,7 +119,7 @@ $libvirt_log = file_exists("/var/log/libvirt/libvirtd.log");   : -
+ @@ -180,7 +180,7 @@ _(Libvirt storage location)_: _(Default VM storage path)_: -: +: _(Modify with caution: unable to validate path until Array is Started)_ @@ -188,7 +188,7 @@ _(Default VM storage path)_: :vms_libvirt_storage_help: _(Default ISO storage path)_: -: +: _(Modify with caution: unable to validate path until Array is Started)_ @@ -364,6 +364,64 @@ function btrfsScrub(path) { } }); } + +function validatePath(input) { + if (input.value.includes("'")) { + input.setCustomValidity(_("Single quote ' is not allowed in the path.")_); + } else { + input.setCustomValidity(""); + } + input.reportValidity(); +} + +// Validate both domaindir and mediadir on submit +function validateFormOnSubmit() { + const domaindir = document.getElementById('domaindir'); + const mediadir = document.getElementById('mediadir'); + + // Run validation + validatePath(domaindir); + validatePath(mediadir); + + // Check validity in order, and focus the first invalid field + if (!domaindir.checkValidity()) { + domaindir.reportValidity(); + domaindir.focus(); + return false; + } + + if (!mediadir.checkValidity()) { + mediadir.reportValidity(); + mediadir.focus(); + return false; + } + + // Both valid + return true; +} + +document.getElementById('settingsForm').addEventListener('submit', function(e) { + if (!validateFormOnSubmit()) { + e.preventDefault(); + } +}); + +// Attach validation on input events +['domaindir', 'mediadir'].forEach(id => { + const input = document.getElementById(id); + input.addEventListener('input', () => validatePath(input)); +}); + +// Hook into Unraid fileTreeAttach for both fields +$('.filepicker').each(function() { + const input = this; + $(input).fileTreeAttach(null, null, function(folder) { + $(input).val(folder); + validatePath(input); + $(document).trigger('close.fileTree'); + }); +}); + $(function(){ $.post("/plugins/dynamix.vm.manager/include/Fedora-virtio-isos.php",{},function(isos) { $('#winvirtio_select').html(isos).prop('disabled',false).change().each(function(){$(this).on('change',function() {