-
Notifications
You must be signed in to change notification settings - Fork 136
re-validating not triggering properly #235
Comments
Hi @benmonro, My test case: let Latitude = t.refinement(t.Number, num => num >= -90 && num <= 90, 'latitude');
Latitude.getValidationErrorMessage = function(value, path, context) {
if (!Latitude.is(value)) {
return `${value} is not a valid latitude value`;
}
};
const Type = t.struct({
latitude: Latitude
});
const App = React.createClass({
onSubmit(evt) {
evt.preventDefault();
var value = this.refs.form.getValue();
if (value) {
console.log(value);
}
},
render() {
return (
<form onSubmit={this.onSubmit}>
<t.form.Form
ref="form"
type={Type}
/>
<div className="form-group">
<button type="submit" className="btn btn-primary">Save</button>
</div>
</form>
);
}
}); My steps:
displays correctly "abc is not a valid latitude value"
displays correctly "91 is not a valid latitude value"
displays correctly "91 is not a valid latitude value" |
oh I forgot to mention that I am overriding the error message for number:
Also i'm using a custom template / skin... |
Once again this is working fine for me: t.Number.getValidationErrorMessage = function(value) {
return !value ? 'number required' : 'blah';
};
let Latitude = t.refinement(t.Number, num => num >= -90 && num <= 90, 'latitude');
Latitude.getValidationErrorMessage = function(value, path, context) {
if (!Latitude.is(value)) {
return `${value} is not a valid latitude value`;
}
};
const Type = t.struct({
latitude: Latitude
}); My steps:
displays correctly "blah"
displays correctly "91 is not a valid latitude value"
displays correctly "91 is not a valid latitude value" So maybe the problem is in your custom template, but it seems weird. |
hmm, ok. any chance you can post the standalone version of tcomb with each build? I might be able to put it together in a jsbin.. |
I found a failing test case containing refinements of structs, working on this... |
Oh good thought I was going crazy
|
Not sure if it's your same issue though: const predicate = (x) => x.a > 10 && x.a < 20;
const Type = t.refinement(t.struct({
a: t.Number
}), predicate);
Type.getValidationErrorMessage = function (x) {
if (x.a <= 10) {
return '10';
}
if (x.a >= 20) {
return '20';
}
};
Your issue seems to regard a refinement of a number instead of a refinement of a struct... |
That is correct. I'm refining a number
|
Ok, just pushed a fix for my failing test case to master, let's see how it goes. Could you please give it a try? |
the previous code would lead to bugs regarding error messages when the type is a subtype of a struct, gcanti/tcomb-form#235
Fixed in v0.6.10 and v0.7.6 |
@gcanti I believe I may have found another issue related to a fix you did here: #230
suppose I have the following code:
If i call form.validate() on this, it correctly renders my error message (thanks for that fix). However, if I change the data to something else invalid click save again (which runs validate() again), the first error message is displayed, rather than the 2nd. For example. If i enter a string like "abc" it will show me the error saying that 'abc' is not a valid number. But then if I change the value to 91, instead of saying '91 is not a valid latitude value' it keeps the previous message that abc is not a valid number.
The text was updated successfully, but these errors were encountered: