Skip to content

Commit 867f44d

Browse files
committed
Cast e.target.value with parseInt/Float when relevant
1 parent 8910fd7 commit 867f44d

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [0.0.11] - 2025-04-08
2+
3+
- Print out stringified errors for unexpected errors
4+
- Cast e.target.value with parseInt/parseFloat when appropriate
5+
16
## [0.0.10] - 2025-04-08
27

38
- Do not double up hashes on Outcome import

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
foobara-typescript-react-command-form-generator (0.0.10)
4+
foobara-typescript-react-command-form-generator (0.0.11)
55
foobara-typescript-remote-command-generator (~> 0.0.1)
66

77
GEM
@@ -14,7 +14,7 @@ GEM
1414
diff-lcs (1.6.1)
1515
docile (1.4.1)
1616
ffi (1.17.1-x86_64-linux-gnu)
17-
foobara (0.0.95)
17+
foobara (0.0.96)
1818
bigdecimal
1919
foobara-lru-cache (~> 0.0.2)
2020
foobara-util (~> 0.0.11)

src/typescript_react_command_form_generator.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,23 @@ def html_input
242242
#{one_of.map { |value| "<option value=\"#{value}\">#{value}</option>" }.join}
243243
</select>"
244244
else
245+
type = type_declaration.to_type
246+
247+
cast_value = if type.name.to_s == "integer" || type.extends_symbol?(:integer)
248+
"parseInt(e.target.value)"
249+
elsif type.name.to_s == "float" || type.extends_symbol?(:float)
250+
# TODO: test this path
251+
# :nocov:
252+
"parseFloat(e.target.value)"
253+
# :nocov:
254+
else
255+
"e.target.value"
256+
end
257+
245258
"<input
246259
#{"type=\"password\"" if sensitive?}
247260
value={#{name} ?? \"\"}
248-
onChange={(e) => { set#{name_upcase}(e.target.value) }}
261+
onChange={(e) => { set#{name_upcase}(#{cast_value}) }}
249262
placeholder=\"#{name_english}\"
250263
/>"
251264
end

version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Foobara
22
module Generators
33
module TypescriptReactCommandFormGenerator
4-
VERSION = "0.0.10".freeze
4+
VERSION = "0.0.11".freeze
55

66
local_ruby_version = File.read("#{__dir__}/.ruby-version").chomp
77
local_ruby_version_minor = local_ruby_version[/\A(\d+\.\d+)\.\d+\z/, 1]

0 commit comments

Comments
 (0)