Always populate the monitorNames object, and check for duplicate names when saving an existing Monitor as well as new monitors

This commit is contained in:
Isaac Connor 2018-01-22 11:42:52 -05:00
parent 97595051ce
commit 8a27ea3a04
1 changed files with 4 additions and 7 deletions

View File

@ -34,17 +34,14 @@ controlOptions[<?php echo $row['Id'] ?>][<?php echo $i ?>] = '<?php echo transla
} }
?> ?>
<?php
if ( empty($_REQUEST['mid']) ) {
?>
var monitorNames = new Object(); var monitorNames = new Object();
<?php <?php
foreach ( dbFetchAll( "select Name from Monitors order by Name asc", "Name" ) as $name ) { $query = empty($_REQUEST['mid']) ? dbQuery('SELECT Name FROM Monitor') : dbQuery('SELECT Name FROM Monitors WHERE Id != ?', array($_REQUEST['mid']) );
while ( $name = dbFetchNext($query, 'Name') ) {
?> ?>
monitorNames['<?php echo validJsStr($name) ?>'] = true; monitorNames['<?php echo validJsStr($name) ?>'] = true;
<?php <?php
} } // end foreach
}
?> ?>
function validateForm( form ) { function validateForm( form ) {
@ -52,7 +49,7 @@ function validateForm( form ) {
if ( form.elements['newMonitor[Name]'].value.search( /[^\w\-\.\(\)\:\/ ]/ ) >= 0 ) if ( form.elements['newMonitor[Name]'].value.search( /[^\w\-\.\(\)\:\/ ]/ ) >= 0 )
errors[errors.length] = "<?php echo translate('BadNameChars') ?>"; errors[errors.length] = "<?php echo translate('BadNameChars') ?>";
else if ( form.elements.mid.value == 0 && monitorNames[form.elements['newMonitor[Name]'].value] ) else if ( monitorNames[form.elements['newMonitor[Name]'].value] )
errors[errors.length] = "<?php echo translate('DuplicateMonitorName') ?>"; errors[errors.length] = "<?php echo translate('DuplicateMonitorName') ?>";
if ( form.elements['newMonitor[AnalysisFPSLimit]'].value && !(parseFloat(form.elements['newMonitor[AnalysisFPSLimit]'].value) > 0 ) ) if ( form.elements['newMonitor[AnalysisFPSLimit]'].value && !(parseFloat(form.elements['newMonitor[AnalysisFPSLimit]'].value) > 0 ) )