Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates the min/max parsing to check for empty attributes #18

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ typings/
# Yarn Integrity file
.yarn-integrity

# Yarn 2 files and folders
.yarn
.yarnrc.yml

# dotenv environment variables file
.env
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
13 changes: 5 additions & 8 deletions dist/jquery.nice-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,15 @@
// Skip already initialized input
if ($currentInput.attr('data-nice-number-initialized')) return;

var isValidMax = maxValue !== '' && maxValue !== undefined && maxValue !== false;
var isValidMin = minValue !== '' && minValue !== undefined && minValue !== false;

// Handle max and min values
if (
maxValue !== undefined &&
maxValue !== false
) {
if (isValidMax) {
attrMax = parseFloat(maxValue);
}

if (
minValue !== undefined &&
minValue !== false
) {
if (isValidMin) {
attrMin = parseFloat(minValue);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.nice-number.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ <h3>
</h3>
<pre>
<code>
&lt;input type="number" id="callback"&gt;
&lt;output id="callbackOutput"&gt;&lt;output&gt;
&lt;input type="number" id="callback"&gt;
&lt;output id="callbackOutput"&gt;&lt;output&gt;
</code>
</pre>
<pre>
Expand All @@ -69,6 +69,15 @@ <h3>
<input type="number" id="callback" />
<output id="callbackOutput"></output>
</div>
<div>
<h2>Handles empty min or max attributes</h2>
<pre>
<code>
&lt;input type="number" min="" max="" class="number" />
</code>
</pre>
<input type="number" min="" max="" class="number" />
</div>
<!-- Dependencies -->
<script src="../node_modules/jquery/dist/jquery.min.js"></script>

Expand Down
13 changes: 5 additions & 8 deletions src/jquery.nice-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,15 @@
// Skip already initialized input
if ($currentInput.attr('data-nice-number-initialized')) return;

var isValidMax = maxValue !== '' && maxValue !== undefined && maxValue !== false;
var isValidMin = minValue !== '' && minValue !== undefined && minValue !== false;

// Handle max and min values
if (
maxValue !== undefined &&
maxValue !== false
) {
if (isValidMax) {
attrMax = parseFloat(maxValue);
}

if (
minValue !== undefined &&
minValue !== false
) {
if (isValidMin) {
attrMin = parseFloat(minValue);
}

Expand Down
Loading