Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions numericInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
var min = settings.min;
var max = settings.max;

if(min == max)
if(min !== undefined && max !== undefined && min == max)
{
throw("The minimum value cannot be the same as the max value");
}
Expand Down Expand Up @@ -59,7 +59,7 @@

else if (allowNegative == true && inputCode == 45) // Conditions for a decimal point
{
if(currentValue.charAt(0) == '-')
if(currentValue.charAt(0) == '-' && getSelectEnd(this) == 0)
return false;

if(getCaret(this) != 0)
Expand All @@ -75,7 +75,7 @@

else if(inputCode > 0 && (inputCode >= 48 && inputCode <= 57)) // Disallows numbers before a negative.
{
if (allowNegative == true && currentValue.charAt(0) == '-' && getCaret(this) == 0)
if (allowNegative == true && currentValue.charAt(0) == '-' && getCaret(this) == 0 && getSelectEnd(this) == 0)
return false;
}
});
Expand Down Expand Up @@ -133,4 +133,12 @@

return 0;
};

function getSelectEnd(element)
{
if (element.selectionEnd)
return element.selectionEnd;
else
return 0;
}
}( jQuery ));