react-json icon indicating copy to clipboard operation
react-json copied to clipboard

Docs Missing for Validation and Settings

Open zthomas opened this issue 10 years ago • 1 comments

Gotta say, love this! I'm really looking forward to including it on my upcoming project.

I just noticed that the docs for validation and settings are missing. https://github.com/arqex/react-json/blob/master/docs/docs.md

If would be super helpful if you can upload them. Or if you can give a quick example of validation that'd be appreciated.

zthomas avatar Jul 18 '15 22:07 zthomas

Hi @zthomas

I'm glad you liked it, but this project is still in an alpha stage. That is why there are no much docs about it, beside the ones you can find in

https://github.com/arqex/react-json/tree/master/docs

Those are not really complete.

The worst part of having something in an alpha stage is that the API can change at any time and validation is one of the things to settle down.

Currently, to validate a react-json form we need to have a reference to it:

var MyComp = React.createClass({
    render: function(){
        var settings = {
            form: true,
            fields: { age: { validates: "required integer[18, 99]" }}
        }
        <Json ref="myJson" value={ { age: 22 } } settings={ settings } onChange={ this.update }/>
    }
    update: function( jsonValue ){
        console.log( this.refs.myJson.getValidationErrors() );
    }
});

getValidationErrors() will check if the validates setting for the field is fulfilled and highlight the errors. You can have more info reading https://github.com/arqex/react-json/blob/master/src/validation.js

Of course, any kind of feedback is always welcome. :)

arqex avatar Jul 22 '15 16:07 arqex