Added validation of input color codes
parent
33911ed7e0
commit
76e8e2809b
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue