Comments (8)
@oguzbilgic for nested attributes, I have found it's almost always better to ignore your database model, and instead model your form as flat as possible.
As an example, assuming Person has_one Address, instead of doing this <input name="person[address][street_address]" />
, just do <input name="person[street_address]" />
and figure it out on the server. For me, this has been true with and without React. I usually create an object that maps my REST-resource to the backend database models. That way, when the app grows and the backend modeling needs to change, it's much easier to change the way my REST-to-Database models work, rather than all the forms that interact with those models.
@eliotsykes sorry for missing your question. The form tag turned out to be very simple, so I never bothered making a PR for it. I posted a gist of my form helper. I never found a way to build Rails.FormErrorList
that I really thought was re-usable, and the others are so trivial that adding them felt like it would just clutter the framework.
from react-rails.
I think it would be better to release it as a separate gem. Anyway, i totally up for it, as i had similar thoughts about Rails-specific components.
from react-rails.
@xionon I'd be interested in seeing any work-in-progress code for these helpers, they sound useful.
from react-rails.
I am also working on something similar. But the real issue is input naming, and nested attributes! I would love to hear if you guys found a solution to this.
from react-rails.
This is an awesome idea. 👍
from react-rails.
I also have similar ideas, i posted its here https://github.com/badenkov/react_form_rails
from react-rails.
This may be a terrible idea... but for the server side, what about an API that looks similar to the familiar form_for
Rails helper?
<%= react_form_for @comment, 'CommentForm' %>
This would exist for the purpose of passing all the props that a <Rails.form />
component may need. It may generate something like:
<div data-react-class="CommentForm" data-react-props="{ RailsForm: { action: '/comments', csrfToken: 'foo', etc: '...' }, object: { comment: 'properties', would: 'be here' }" />
In my initial thinking, the object
key would have @comment.to_json
. And if that isn't what you want, a third optional parameter could be passed, to explicitly state object
props.
Then, on the component side, we can use Rails
components to build forms in a familiar way, adding behavior as we need it.
var CommentForm = React.createClass({
propTypes: {
RailsForm: React.PropTypes.shape({
action: React.PropTypes.string.isRequired,
csrfToken: React.PropTypes.string.isRequired,
isNewRecord: React.PropTypes.bool.isRequied,
errors: React.PropTypes.arrayOf(React.PropTypes.object),
}),
object: React.PropTypes.object.isRequred,
},
render() {
<Rails.form {...this.props.RailsForm}>
<Rails.label attr="text" />
<Rails.inputField attr="text" onChange={this.handleTextChange" />
</Rails>
},
handleTextChange() {
/* validate? */
}
})
from react-rails.
This would be a cool project, if anyone gets it going, please send a PR to the "Related Projects" section!
https://github.com/reactjs/react-rails#related-projects
from react-rails.
Related Issues (20)
- Import react_component but it' shown HOT 2
- compare/contrast and migration steps to react_on_rails HOT 5
- Component doesn't render on jsbundling-rails webpacker HOT 5
- Component not loading in rails app HOT 5
- react-rails v3.1.0 is broken HOT 1
- server_rendering.js not found following README HOT 8
- Re-organize documentations in docs folder
- server_rendering.js not found following README HOT 1
- How do I handle styling?
- esbuild HOT 1
- Error related to server_rendering.js not found with SSR HOT 3
- Setup StrictMode for components HOT 2
- get started docs r-r version HOT 1
- Rails 7.1 Renders Partial Header HOT 1
- Server side rendering `window` behaves differently than Node.js? HOT 4
- Issues with Loading React Component for Cuprite in Rails 7.1 HOT 1
- Hooks not working due to Invalid Hook Call HOT 3
- Move react_ujs to es module flow
- Error when use React component other than HelloWorld HOT 1
- Different order for React rendering / DOM ready event in Webkit with React 18 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-rails.