number type doesn't work correctly with tcomb-form-native
Closed this issue · 2 comments
lyahdav commented
For example, if my form structure is defined as:
var TcombType = transform({
"type": "object",
"properties": {
"Age": { "type": "number" }
}
});
When creating a small React Native app using tcomb-form-native after inputting a number into the Age field and calling this.refs.form.getValue()
it's null and it shows a red box around the Age field.
This works fine if I just use tcomb-form-native directly with a structure like:
var TcombType = t.struct({
age: t.Number
});
gcanti commented
Not sure what's the problem, however 2 notes
- The equivalent JSON schema is
{
"type": "object",
"properties": {
"Age": { "type": "number" }
},
"required": ["Age"] // <= !
}
- make sure you are not importing two different copies of
tcomb
(for example runningnpm list tcomb
)
lyahdav commented
I figured this issue out. It was because I had two different versions of tcomb
imported as you suspected.
My package.json
had:
"tcomb-form-native": "0.6.7",
"tcomb-json-schema": "^0.2.5",
Running npm list tcomb
showed:
├─┬ tcomb-form-native@0.6.7
│ └─┬ tcomb-validation@3.3.0
│ └── tcomb@3.2.20
└─┬ tcomb-json-schema@0.2.5
└── tcomb@2.7.0
I updated the package.json
to:
"tcomb-form-native": "0.6.7",
"tcomb-json-schema": "^0.3.0"
Then when running npm list tcomb
it showed:
└─┬ tcomb-json-schema@0.3.0
└── tcomb@3.2.20
Also for the record, the equivalent non JSON schema structure of my original JSON structure is:
t.struct({
age: t.maybe(t.Number)
});