@@ -119,7 +119,7 @@ $libvirt_log = file_exists("/var/log/libvirt/libvirtd.log");
119119
120120: <span><input type="checkbox" class="advancedview"></span>
121121<?endif;?>
122- <form markdown="1" id="settingsForm" method="POST" action="/update.php" target="progressFrame">
122+ <form markdown="1" id="settingsForm" method="POST" action="/update.php" target="progressFrame" onsubmit="return validateFormOnSubmit();" >
123123<input type="hidden" name="#file" value="<?=htmlspecialchars($domain_cfgfile)?>">
124124<input type="hidden" name="#command" value="/plugins/dynamix/scripts/emcmd">
125125<input type="hidden" name="#arg[1]" value="cmdStatus=Apply">
@@ -180,15 +180,15 @@ _(Libvirt storage location)_:
180180
181181<?endif;?>
182182_(Default VM storage path)_:
183- : <input type="text" id="domaindir" name="DOMAINDIR" autocomplete="off" spellcheck="false" data-pickfolders="true" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="/mnt" value="<?=htmlspecialchars($domain_cfg['DOMAINDIR'])?>" placeholder="_(Click to Select)_" pattern="^[^\\]*/$">
183+ : <input type="text" id="domaindir" name="DOMAINDIR" autocomplete="off" spellcheck="false" data-pickfolders="true" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="/mnt" value="<?=htmlspecialchars($domain_cfg['DOMAINDIR'])?>" placeholder="_(Click to Select)_" pattern="^[^\\]*/$" onchange="validatePath(this)" >
184184<?if (!$started):?>
185185 <span><i class="fa fa-warning icon warning"></i> _(Modify with caution: unable to validate path until Array is Started)_</span>
186186<?endif;?>
187187
188188:vms_libvirt_storage_help:
189189
190190_(Default ISO storage path)_:
191- : <input type="text" id="mediadir" name="MEDIADIR" autocomplete="off" spellcheck="false" data-pickfolders="true" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="<?=is_dir('/mnt/user') ? '/mnt/user' : '/mnt'?>" value="<?=htmlspecialchars($domain_cfg['MEDIADIR'])?>" placeholder="_(Click to Select)_" pattern="^[^\\]*/$">
191+ : <input type="text" id="mediadir" name="MEDIADIR" autocomplete="off" spellcheck="false" data-pickfolders="true" data-pickfilter="HIDE_FILES_FILTER" data-pickroot="<?=is_dir('/mnt/user') ? '/mnt/user' : '/mnt'?>" value="<?=htmlspecialchars($domain_cfg['MEDIADIR'])?>" placeholder="_(Click to Select)_" pattern="^[^' \\]*/$">
192192<?if (!$started):?>
193193 <span><i class="fa fa-warning icon warning"></i> _(Modify with caution: unable to validate path until Array is Started)_</span>
194194<?endif;?>
@@ -364,6 +364,64 @@ function btrfsScrub(path) {
364364 }
365365 });
366366}
367+
368+ function validatePath(input) {
369+ if (input.value.includes("'")) {
370+ input.setCustomValidity(_("Single quote ' is not allowed in the path.")_);
371+ } else {
372+ input.setCustomValidity("");
373+ }
374+ input.reportValidity();
375+ }
376+
377+ // Validate both domaindir and mediadir on submit
378+ function validateFormOnSubmit() {
379+ const domaindir = document.getElementById('domaindir');
380+ const mediadir = document.getElementById('mediadir');
381+
382+ // Run validation
383+ validatePath(domaindir);
384+ validatePath(mediadir);
385+
386+ // Check validity in order, and focus the first invalid field
387+ if (!domaindir.checkValidity()) {
388+ domaindir.reportValidity();
389+ domaindir.focus();
390+ return false;
391+ }
392+
393+ if (!mediadir.checkValidity()) {
394+ mediadir.reportValidity();
395+ mediadir.focus();
396+ return false;
397+ }
398+
399+ // Both valid
400+ return true;
401+ }
402+
403+ document.getElementById('settingsForm').addEventListener('submit', function(e) {
404+ if (!validateFormOnSubmit()) {
405+ e.preventDefault();
406+ }
407+ });
408+
409+ // Attach validation on input events
410+ ['domaindir', 'mediadir'].forEach(id => {
411+ const input = document.getElementById(id);
412+ input.addEventListener('input', () => validatePath(input));
413+ });
414+
415+ // Hook into Unraid fileTreeAttach for both fields
416+ $('.filepicker').each(function() {
417+ const input = this;
418+ $(input).fileTreeAttach(null, null, function(folder) {
419+ $(input).val(folder);
420+ validatePath(input);
421+ $(document).trigger('close.fileTree');
422+ });
423+ });
424+
367425$(function(){
368426 $.post("/plugins/dynamix.vm.manager/include/Fedora-virtio-isos.php",{},function(isos) {
369427 $('#winvirtio_select').html(isos).prop('disabled',false).change().each(function(){$(this).on('change',function() {
0 commit comments