Some client side input validation

This commit is contained in:
Xzide 2023-05-28 21:53:23 -04:00
parent 8fcc50b1a4
commit f90c022e7c
2 changed files with 18 additions and 3 deletions

View File

@ -17,15 +17,30 @@ const Startup = (() => {
var width = Util.getValue('size-width' + splashPostfix);
var height = Util.getValue('size-height' + splashPostfix);
var selectedPalette = Util.getText('palette-button' + splashPostfix);
if (!(validator(width) && validator(height))) {
Util.setValue('size-width' + splashPostfix, 64);
Util.setValue('size-height' + splashPostfix, 64);
return;
};
newPixel(FileManager.defaultLPE(width,height));
resetInput();
//track google event
if (typeof ga !== 'undefined')
ga('send', 'event', 'Pixel Editor New', selectedPalette, width+'/'+height); /*global ga*/
}
function validator(param) {
if (Number.isNaN(param) || param.includes('.')) return false
const num = parseInt(param)
if (param != num) return false
if (num && num > 0 && num <= 5000) return true
else return false
}
/** Creates a new, empty file
*
* @param {*} lpe If lpe != null, then the newPixel is being called from the open menu

View File

@ -25,7 +25,7 @@
<h2>Size</h2>
<div class="sp-np-entry">
<input id="size-width-splash" value="{{#if width}}{{width}}{{else}}64{{/if}}" autocomplete="off" />{{svg "x.svg" width="16" height="16" class="dimentions-x"}}<input id="size-height-splash" value="{{#if height}}{{height}}{{else}}64{{/if}}" autocomplete="off" />
<input id="size-width-splash" value="{{#if width}}{{width}}{{else}}64{{/if}}" autocomplete="off" pattern="[0-9]" type="number"/>{{svg "x.svg" width="16" height="16" class="dimentions-x"}}<input id="size-height-splash" value="{{#if height}}{{height}}{{else}}64{{/if}}" autocomplete="off" pattern="[0-9]" type="number"/>
</div>
<h2>Palette</h2>