Closed gcanti closed 9 years ago
The plan:
context
error
error(value, path, context)
getValidationErrorMessage(value, path, context)
Example
const Name = t.subtype(t.String, (s) => s.length > 2); Name.getValidationErrorMessage = function (value, path, context) { return 'error message with locale: ' + context.locale; }; const Schema = t.struct({ name: Name }); const options = { fields: { name: { // error: Name.getValidationErrorMessage // <= no more required } } }; 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={Schema} options={options} context={{locale: 'it-IT'}} // <= new prop /> <button type="submit" className="btn btn-primary">Save</button> </form> ); } });
Great! You rock!
Released https://github.com/gcanti/tcomb-form/releases/tag/v0.7.1
The plan:
v0.7.1
context
toerror
options that are functions (new signature:error(value, path, context)
)error
option default if the type constructor owns agetValidationErrorMessage(value, path, context)
functioncontext
prop to all components (passed intoerror
ascontext
argument)Example