form_props 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cff106aa823f714feedeca5bcb60009c1e699fd3e5caf04213aff7b5453bebf1
4
- data.tar.gz: dec35c8f4b7eaf8233b1dc5ba018b08d2d71275a9e5251e82c18c68190e8b10f
3
+ metadata.gz: e3200a705c61ab6b0ebae4316cb80874b53ee0be1297e1230632e8b4568d7054
4
+ data.tar.gz: e0f83bff9ce077fee68002cedc1a0906d4139aff509fe514c73a4e085c82a386
5
5
  SHA512:
6
- metadata.gz: 3bfdfa243ba6534c73b837472bd1e9718b19ca0c99ecc7cc177389a6d4474c4042a634f5ac2a0f68e32484b6895e024b433266d7c670cda6199dfa0a82929154
7
- data.tar.gz: 5afc0d65c6d09a6bbfde9c31dc9fc489499cfa69f489cd45626ebf4342da1bd1e8524ec4fab46af87d6778cef9fd445a2b45585d7462143298a113fc13efcb94
6
+ metadata.gz: 6054204836874c8cebb5fa3f9cfd6f84fb3cb5c96f27ac9945683dc5e2aac73fe4be3a652dd64d3cfab33bfc70703fb2283fcf553d1908eaba46a0b4c10a8c7c
7
+ data.tar.gz: d586f6ebb862c1e75fe55056cdf7138dc72db2a0e3f2c847563524d2889d44b5afb16dc4135681b7524e80c4d2081ae08719fdd46951e3a14631fa73fa84a504
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # Form Props
2
2
 
3
- ![Build Status](https://github.com/github/docs/actions/workflows/build.yml/badge.svg?branch=main)
3
+ ![Build Status](https://github.com/thoughtbot/form_props/actions/workflows/build.yml/badge.svg?branch=main)
4
4
 
5
- FormProps is a Rails form builder that outputs HTML attributes instead of tags.
6
- Now you can enjoy the conviences of Rails helpers in other view libraries like
7
- React, and React Native.
5
+ FormProps is a Rails form builder that outputs HTML props instead of tags. Now
6
+ you can enjoy the power and convenience of Rails helpers in React!
8
7
 
9
8
  By separting attributes from tags, FormProps can offer greater flexbility than normal
10
9
  Rails form builders; allowing designers to stay longer in HTML land and more easily
@@ -26,7 +25,7 @@ gem "form_props"
26
25
  and `bundle install`
27
26
 
28
27
  ## Usage
29
- `form_props` is designed to be used in a [PropsTemplate] template (it can work with
28
+ `form_props` is designed to be used in a [PropsTemplate] template (it can work with
30
29
  [jbuilder](#jbuilder)). For example in your `new.json.props`:
31
30
 
32
31
  ```ruby
@@ -46,7 +45,7 @@ would output
46
45
  props: {
47
46
  id: "create-post",
48
47
  action: "/posts/123",
49
- accept-charset: "UTF-8",
48
+ acceptCharset: "UTF-8",
50
49
  method: "post"
51
50
  },
52
51
  extras: {
@@ -54,19 +53,19 @@ would output
54
53
  name: "_method",
55
54
  type: "hidden",
56
55
  defaultValue: "patch",
57
- autocomplete: "off"
56
+ autoComplete: "off"
58
57
  },
59
58
  utf8: {
60
59
  name: "utf8",
61
60
  type: "hidden",
62
61
  defaultValue: "\u0026#x2713;",
63
- autocomplete: "off"
62
+ autoComplete: "off"
64
63
  }
65
64
  csrf: {
66
65
  name: "utf8",
67
66
  type: "authenticity_token",
68
67
  defaultValue: "SomeTOken!23$",
69
- autocomplete: "off"
68
+ autoComplete: "off"
70
69
  }
71
70
  },
72
71
  inputs: {
@@ -84,12 +83,11 @@ import React from 'react'
84
83
 
85
84
  export default ({props, inputs, extras}) => {
86
85
  <form {...props}>
87
- {Object.values(extras).map((hiddenProps) => (<input {...hiddenProps} type="hidden"/>))}
86
+ {Object.values(extras).map((hiddenProps) => (<input {...hiddenProps} key={hiddenProps.name}/>))}
88
87
 
89
- <input {...inputs.title} type="text"/>
88
+ <input {...inputs.title} />
90
89
  <label for={inputs.title.id}>Your Name</label>
91
-
92
- <input {...inputs.submit} type="submit"/>
90
+ <button {...inputs.submit}>{inputs.submit.text}</button>
93
91
  </form>
94
92
  }
95
93
  ```
@@ -649,7 +647,7 @@ available.
649
647
 
650
648
  ## jbuilder
651
649
 
652
- form_props can work with jbuilder, but needs an extra call in the beginning of
650
+ form_props can work with jbuilder, but needs an extra call in the beginning of
653
651
  your template to `FormProps.set` to inject `json`. For example.
654
652
 
655
653
  ```ruby
@@ -40,6 +40,7 @@ module FormProps
40
40
  end
41
41
 
42
42
  html_options = html_options_for_form_with(url, model, **options)
43
+ html_options["acceptCharset"] ||= html_options.delete("accept-charset")
43
44
 
44
45
  json.extras do
45
46
  extra_props_for_form(json, html_options)
@@ -62,7 +63,7 @@ module FormProps
62
63
  json.name request_forgery_protection_token.to_s
63
64
  json.type "hidden"
64
65
  json.default_value token
65
- json.autocomplete "off"
66
+ json.auto_complete "off"
66
67
  end
67
68
  end
68
69
  end
@@ -72,7 +73,7 @@ module FormProps
72
73
  json.name "_method"
73
74
  json.type "hidden"
74
75
  json.default_value method.to_s
75
- json.autocomplete "off"
76
+ json.auto_complete "off"
76
77
  end
77
78
  end
78
79
 
@@ -81,7 +82,7 @@ module FormProps
81
82
  json.name "utf8"
82
83
  json.type "hidden"
83
84
  json.default_value "&#x2713;"
84
- json.autocomplete "off"
85
+ json.auto_complete "off"
85
86
  end
86
87
  end
87
88
 
@@ -132,7 +132,7 @@ module FormProps
132
132
  def submit(value = nil, options = {})
133
133
  value, options = nil, value if value.is_a?(Hash)
134
134
  value ||= submit_default_value
135
- options = {name: "commit", value: value}.update(options)
135
+ options = {name: "commit", text: value}.update(options)
136
136
 
137
137
  Inputs::Submit.new(@template, options).render
138
138
  end
@@ -140,6 +140,7 @@ module FormProps
140
140
  def fields_for_with_nested_attributes(association_name, association, options, block)
141
141
  name = "#{object_name}[#{association_name}_attributes]"
142
142
  association = convert_to_model(association)
143
+ json = @template.instance_variable_get(:@__json)
143
144
 
144
145
  if association.respond_to?(:persisted?)
145
146
  association = [association] if @object.public_send(association_name).respond_to?(:to_ary)
@@ -150,8 +151,8 @@ module FormProps
150
151
  if association.respond_to?(:to_ary)
151
152
  explicit_child_index = options[:child_index]
152
153
 
153
- @template.json.set!("#{association_name}_attributes") do
154
- @template.json.array! association do |child|
154
+ json.set!("#{association_name}_attributes") do
155
+ json.array! association do |child|
155
156
  if explicit_child_index
156
157
  options[:child_index] = explicit_child_index.call if explicit_child_index.respond_to?(:call)
157
158
  else
@@ -162,7 +163,7 @@ module FormProps
162
163
  end
163
164
  end
164
165
  elsif association
165
- @template.json.set!("#{association_name}_attributes") do
166
+ json.set!("#{association_name}_attributes") do
166
167
  fields_for_nested_model(name, association, options, block)
167
168
  end
168
169
  end
@@ -4,7 +4,7 @@ module FormProps
4
4
  module Inputs
5
5
  class HiddenField < TextField
6
6
  def render
7
- @options[:autocomplete] = "off"
7
+ @options[:auto_complete] = "off"
8
8
  super
9
9
  end
10
10
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FormProps
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_props
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-13 00:00:00.000000000 Z
11
+ date: 2023-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: '2.5'
109
+ version: '2.7'
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - - ">="