From c490cab4e5d6b67e71ef05954b9eb9ca9ca9a3c1 Mon Sep 17 00:00:00 2001 From: Johny Ho Date: Wed, 7 Oct 2026 13:01:12 +0200 Subject: [PATCH] Update Readme --- README.md | 186 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 134 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 4b39e58..7495c50 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,7 @@ would output ``` { someForm: { - props: { - id: "create-post", + form: { action: "/posts/123", acceptCharset: "UTF-8", method: "post" @@ -65,42 +64,57 @@ would output type: "hidden", defaultValue: "\u0026#x2713;", autoComplete: "off" - } + }, csrf: { - name: "utf8", - type: "authenticity_token", + name: "authenticity_token", + type: "hidden", defaultValue: "SomeTOken!23$", autoComplete: "off" } }, inputs: { title: {name: "post[title]", id: "post_title", type: "text", defaultValue: "hello"}, - submit: {type: "submit", value: "Update a Post"} + submit: {name: "commit", text: "Update Post", type: "submit"} } } } ``` +The `csrf` name is your app's `request_forgery_protection_token`, which is +`authenticity_token` by default. + You can then proceed to use this output in React like so: ```js import React from 'react' -export default ({props, inputs, extras}) => { -
+export default ({form, inputs, extras}) => ( + {Object.values(extras).map((hiddenProps) => ())} - +
-} +) ``` ### Key format -By default, props_template automatically `camelize(:lower)` on all keys. All -documentation here reflects that default. You can change that [behavior](https://github.com/thoughtbot/props_template#change-key-format) -if you wish. +`form_props` formats keys itself, independent of props_template's key format +setting. Attribute names are mapped to their React equivalents (for example, +`class` becomes `className` and `accept-charset` becomes `acceptCharset`), and +the keys under `inputs` are the method names in `camelize(:lower)`, so +`f.datetime_field(:created_at)` is found at `inputs.createdAt`. + +You can override the key of any input with the `key:` option: + +```ruby +form_props(model: @post) do |f| + f.text_field(:title, key: :aTitle) +end +``` + +`inputs.aTitle` would then hold the title field. ## Flexibility form_props is only concerned about attributes, the designer can focus on tag @@ -108,7 +122,7 @@ structure and stay longer in HTML land. For example, you can decide to nest an input inside a label. ```js -