javascript - React form in Rails with validation -
i learn reactjs components , have problem validation have code:
# postform.js.cjsx @postform = react.createclass getinitialstate: -> link: '' errors: '' valid: -> @state.link handlechange: (e) -> name = e.target.name @setstate "#{ name }": e.target.value handlesubmit: (e) -> e.preventdefault() $.ajax method: 'post' url: "/posts/" datatype: 'json' data: post: { link: @state.link } success: (data) => alert('success') error: (data) => errors = data alert('error' + data) render: -> errors = <div id="error_explanation"> <h2>errors prohibited product being saved:</h2> <ul>aaa </ul> </div> react.dom.form classname: 'form-inline' onsubmit: @handlesubmit `[errors]` react.dom.div classname: 'well' react.dom.div classname: 'form-group' react.dom.input type: 'text' classname: 'form-control' placeholder: 'link' name: 'link' value: @state.link onchange: @handlechange react.dom.button type: 'submit' classname: 'btn btn-primary' disabled: !@valid() 'send link'
how can validate link field in view add bootstrap error-class , put info validation problem rails? payload on post, when invalid:
{"link":["is invalid"]}
and question - how can improve speed writing reactjs forms, or other components simple_form in rails?
Comments
Post a Comment