Skip to content
Permalink
Browse files

Added validation of input color codes

  • Loading branch information...
davidjgraph committed Jun 12, 2019
1 parent 33911ed commit 76e8e2809b622659a9c5ffdc4f19922b7a68cfa3
Showing with 11 additions and 4 deletions.
  1. +11 −4 javascript/examples/grapheditor/www/js/Dialogs.js
@@ -204,14 +204,21 @@ var ColorDialog = function(editorUi, color, apply, cancelFn)
var applyBtn = mxUtils.button(mxResources.get('apply'), function()
{
var color = input.value;
ColorDialog.addRecentColor(color, 12);
// https://stackoverflow.com/questions/8027423/how-to-check-if-a-string-is-a-valid-hex-color-representation/8027444
var colorValid = /(^#?[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color);

if (color != 'none' && color.charAt(0) != '#')
if (colorValid)
{
color = '#' + color;
ColorDialog.addRecentColor(color, 12);

if (color != 'none' && color.charAt(0) != '#')
{
color = '#' + color;
}

applyFunction(color);
}

applyFunction(color);
editorUi.hideDialog();
});
applyBtn.className = 'geBtn gePrimaryBtn';

0 comments on commit 76e8e28

Please sign in to comment.
You can’t perform that action at this time.