Skip to content

Commit

Permalink
Cast value to string
Browse files Browse the repository at this point in the history
  • Loading branch information
boptom committed Apr 9, 2024
1 parent 26d97ae commit e0953d6
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ The prefix, thousands separator, decimal character, precision and suffix can be
Alpine JS along with the magics can be utilized to transform inputs to numbers before submitting a form.

```js
<div x-data="{ amount: '10000', formData: {} }" class="space-y-4">
<div x-data="{ amount: 10000, formData: {} }" class="space-y-4">
<form @submit.prevent="formData = { amount: $toNumber(amount) }">
<label for="form-example" class="mr-2">Amount:</label>
<input
Expand Down
2 changes: 1 addition & 1 deletion dist/number.esm.js

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

2 changes: 1 addition & 1 deletion dist/number.min.js

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

4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ <h2 class="font-semibold mb-2">Form Example</h2>

<div class="font-mono rounded-lg p-3 bg-gray-100 my-6 overflow-scroll">
<pre class="max-w-12">
&lt;div x-data=&quot;{ amount: '10000', formData: {} }&quot; class=&quot;space-y-4&quot;&gt;
&lt;div x-data=&quot;{ amount: 10000, formData: {} }&quot; class=&quot;space-y-4&quot;&gt;

&lt;form <span class="text-red-500">@submit.prevent=&quot;formData = { amount: $toNumber(amount) }&quot;</span>&gt;
&lt;label for=&quot;form-example&quot; class=&quot;mr-2&quot;&gt;Amount:&lt;/label&gt;
Expand All @@ -251,7 +251,7 @@ <h2 class="font-semibold mb-2">Form Example</h2>
&lt;/div&gt;</pre>
</div>

<div x-data="{ amount: '10000', formData: {} }" class="space-y-4">
<div x-data="{ amount: 10000, formData: {} }" class="space-y-4">
<form @submit.prevent="formData = { amount: $toNumber(amount) }">
<label for="form-example" class="mr-2">Amount:</label>
<input
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alpinejs-number",
"version": "1.0.1",
"version": "1.0.2",
"description": "Enhanced Numeric Input for Alpine.js: Simplifying Number Formatting and Currency Handling.",
"homepage": "https://boptom.github.io/alpinejs-number",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default function (Alpine) {
// Returns a number from a number string
Alpine.magic("toNumber", () => (value, decimalChar = ".", precision = -1) => {
return Number(
toNumber(value, 0, false, {
toNumber(String(value), 0, false, {
decimalChar,
precision,
unsigned: false,
Expand Down

0 comments on commit e0953d6

Please sign in to comment.