inertia_rails 3.4.0 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +17 -13
- data/lib/generators/inertia/controller/controller_generator.rb +18 -0
- data/lib/generators/inertia/controller/templates/controller.rb.tt +10 -0
- data/lib/generators/inertia/install/frameworks.yml +98 -0
- data/lib/generators/inertia/install/helpers.rb +51 -0
- data/lib/generators/inertia/install/install_generator.rb +291 -0
- data/lib/generators/inertia/install/js_package_manager.rb +50 -0
- data/lib/generators/inertia/install/templates/assets/inertia.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/react.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/svelte.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/vite_ruby.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/vue.svg +1 -0
- data/lib/generators/{inertia_rails/install → inertia/install/templates}/controller.rb +3 -1
- data/lib/generators/inertia/install/templates/dev +23 -0
- data/lib/generators/inertia/install/templates/initializer.rb +6 -0
- data/lib/generators/inertia/install/templates/react/InertiaExample.jsx +60 -0
- data/lib/generators/inertia/install/templates/react/InertiaExample.module.css +80 -0
- data/lib/generators/inertia/install/templates/react/InertiaExample.tsx +60 -0
- data/lib/generators/inertia/install/templates/react/inertia.js +45 -0
- data/lib/generators/inertia/install/templates/react/inertia.ts +51 -0
- data/lib/generators/inertia/install/templates/react/tsconfig.app.json +27 -0
- data/lib/generators/inertia/install/templates/react/tsconfig.json +11 -0
- data/lib/generators/inertia/install/templates/react/tsconfig.node.json +13 -0
- data/lib/generators/inertia/install/templates/react/vite-env.d.ts +1 -0
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +112 -0
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte +112 -0
- data/lib/generators/inertia/install/templates/svelte/inertia.js +44 -0
- data/lib/generators/inertia/install/templates/svelte/inertia.ts.tt +45 -0
- data/lib/generators/inertia/install/templates/svelte/svelte.config.js +7 -0
- data/lib/generators/inertia/install/templates/svelte/tsconfig.json +21 -0
- data/lib/generators/inertia/install/templates/svelte/tsconfig.node.json +12 -0
- data/lib/generators/inertia/install/templates/svelte/vite-env.d.ts +2 -0
- data/lib/generators/inertia/install/templates/svelte4/InertiaExample.svelte +116 -0
- data/lib/generators/inertia/install/templates/svelte4/InertiaExample.ts.svelte +116 -0
- data/lib/generators/inertia/install/templates/svelte4/inertia.js +43 -0
- data/lib/generators/inertia/install/templates/svelte4/inertia.ts.tt +44 -0
- data/lib/generators/inertia/install/templates/svelte4/svelte.config.js +7 -0
- data/lib/generators/inertia/install/templates/svelte4/tsconfig.json +21 -0
- data/lib/generators/inertia/install/templates/svelte4/tsconfig.node.json +12 -0
- data/lib/generators/inertia/install/templates/svelte4/vite-env.d.ts +2 -0
- data/lib/generators/inertia/install/templates/tailwind/application.css +13 -0
- data/lib/generators/inertia/install/templates/tailwind/postcss.config.js +6 -0
- data/lib/generators/inertia/install/templates/tailwind/tailwind.config.js.tt +18 -0
- data/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue +117 -0
- data/lib/generators/inertia/install/templates/vue/InertiaExample.vue +117 -0
- data/lib/generators/inertia/install/templates/vue/inertia.js +35 -0
- data/lib/generators/inertia/install/templates/vue/inertia.ts +35 -0
- data/lib/generators/inertia/install/templates/vue/tsconfig.app.json +24 -0
- data/lib/generators/inertia/install/templates/vue/tsconfig.json +11 -0
- data/lib/generators/inertia/install/templates/vue/tsconfig.node.json +22 -0
- data/lib/generators/inertia/install/templates/vue/vite-env.d.ts +1 -0
- data/lib/generators/inertia/scaffold/scaffold_generator.rb +16 -0
- data/lib/generators/inertia/scaffold_controller/scaffold_controller_generator.rb +60 -0
- data/lib/generators/inertia/scaffold_controller/templates/controller.rb.tt +100 -0
- data/lib/generators/inertia_templates/controller/controller_generator.rb +12 -0
- data/lib/generators/inertia_templates/controller/templates/react/view.jsx.tt +8 -0
- data/lib/generators/inertia_templates/controller/templates/react/view.tsx.tt +8 -0
- data/lib/generators/inertia_templates/controller/templates/svelte/view.svelte.tt +2 -0
- data/lib/generators/inertia_templates/controller/templates/svelte4/view.svelte.tt +2 -0
- data/lib/generators/inertia_templates/controller/templates/vue/view.vue.tt +4 -0
- data/lib/generators/inertia_templates/scaffold/scaffold_generator.rb +12 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Edit.jsx.tt +35 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Edit.tsx.tt +40 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Form.jsx.tt +111 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Form.tsx.tt +130 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Index.jsx.tt +26 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Index.tsx.tt +32 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/New.jsx.tt +27 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/New.tsx.tt +32 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/One.jsx.tt +26 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/One.tsx.tt +32 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Show.jsx.tt +32 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Show.tsx.tt +38 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/types.ts.tt +19 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.svelte.tt +36 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.ts.svelte.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.svelte.tt +97 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.ts.svelte.tt +102 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.svelte.tt +35 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.ts.svelte.tt +39 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/New.svelte.tt +29 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/New.ts.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/One.svelte.tt +28 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/One.ts.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.svelte.tt +35 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.ts.svelte.tt +39 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/types.ts.tt +19 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.svelte.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt +38 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.svelte.tt +96 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.ts.svelte.tt +106 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.svelte.tt +36 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.ts.svelte.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/New.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/New.ts.svelte.tt +31 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/One.ts.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.svelte.tt +39 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.ts.svelte.tt +40 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/types.ts.tt +19 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Edit.ts.vue.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Edit.vue.tt +36 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Form.ts.vue.tt +101 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Form.vue.tt +94 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Index.ts.vue.tt +35 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Index.vue.tt +31 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/New.ts.vue.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/New.vue.tt +29 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/One.ts.vue.tt +28 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/One.vue.tt +26 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Show.ts.vue.tt +41 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Show.vue.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/types.ts.tt +19 -0
- data/lib/generators/inertia_tw_templates/controller/controller_generator.rb +12 -0
- data/lib/generators/inertia_tw_templates/controller/templates/react/view.jsx.tt +8 -0
- data/lib/generators/inertia_tw_templates/controller/templates/react/view.tsx.tt +8 -0
- data/lib/generators/inertia_tw_templates/controller/templates/svelte/view.svelte.tt +2 -0
- data/lib/generators/inertia_tw_templates/controller/templates/svelte4/view.svelte.tt +2 -0
- data/lib/generators/inertia_tw_templates/controller/templates/vue/view.vue.tt +4 -0
- data/lib/generators/inertia_tw_templates/scaffold/scaffold_generator.rb +12 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Edit.jsx.tt +42 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Edit.tsx.tt +47 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.jsx.tt +122 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.tsx.tt +142 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Index.jsx.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Index.tsx.tt +49 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/New.jsx.tt +30 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/New.tsx.tt +35 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/One.jsx.tt +26 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/One.tsx.tt +32 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Show.jsx.tt +47 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Show.tsx.tt +53 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/types.ts.tt +19 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.svelte.tt +44 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.ts.svelte.tt +45 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.svelte.tt +118 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.ts.svelte.tt +123 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.svelte.tt +42 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.ts.svelte.tt +46 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.svelte.tt +32 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.ts.svelte.tt +33 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.svelte.tt +28 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.ts.svelte.tt +30 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.svelte.tt +50 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.ts.svelte.tt +54 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/types.ts.tt +19 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.svelte.tt +45 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt +46 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.svelte.tt +120 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.ts.svelte.tt +130 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Index.svelte.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Index.ts.svelte.tt +44 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/New.svelte.tt +33 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/New.ts.svelte.tt +34 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/One.ts.svelte.tt +30 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Show.svelte.tt +51 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Show.ts.svelte.tt +52 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/types.ts.tt +19 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Edit.ts.vue.tt +45 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Edit.vue.tt +44 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.ts.vue.tt +134 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.vue.tt +127 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Index.ts.vue.tt +47 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Index.vue.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/New.ts.vue.tt +33 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/New.vue.tt +32 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/One.ts.vue.tt +28 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/One.vue.tt +26 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Show.ts.vue.tt +53 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Show.vue.tt +49 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/types.ts.tt +19 -0
- data/lib/inertia_rails/always_prop.rb +6 -0
- data/lib/inertia_rails/base_prop.rb +14 -0
- data/lib/inertia_rails/configuration.rb +4 -1
- data/lib/inertia_rails/controller.rb +16 -4
- data/lib/inertia_rails/defer_prop.rb +21 -0
- data/lib/inertia_rails/generators/controller_template_base.rb +63 -0
- data/lib/inertia_rails/generators/helper.rb +139 -0
- data/lib/inertia_rails/generators/scaffold_template_base.rb +45 -0
- data/lib/inertia_rails/ignore_on_first_load_prop.rb +6 -0
- data/lib/inertia_rails/inertia_rails.rb +34 -12
- data/lib/inertia_rails/lazy_prop.rb +24 -0
- data/lib/inertia_rails/merge_prop.rb +14 -0
- data/lib/inertia_rails/middleware.rb +7 -2
- data/lib/inertia_rails/optional_prop.rb +6 -0
- data/lib/inertia_rails/renderer.rb +106 -20
- data/lib/inertia_rails/version.rb +1 -1
- data/lib/inertia_rails.rb +2 -0
- data/lib/patches/better_errors.rb +10 -8
- data/lib/patches/debug_exceptions/patch-5-0.rb +7 -3
- data/lib/patches/debug_exceptions/patch-5-1.rb +7 -3
- data/lib/patches/mapper.rb +9 -5
- data/lib/patches/request.rb +10 -6
- metadata +185 -13
- data/lib/generators/inertia_rails/install/react/InertiaExample.jsx +0 -9
- data/lib/generators/inertia_rails/install/react/inertia.jsx +0 -17
- data/lib/generators/inertia_rails/install/svelte/InertiaExample.svelte +0 -11
- data/lib/generators/inertia_rails/install/svelte/inertia.js +0 -14
- data/lib/generators/inertia_rails/install/vue/InertiaExample.vue +0 -11
- data/lib/generators/inertia_rails/install/vue/inertia.js +0 -20
- data/lib/generators/inertia_rails/install_generator.rb +0 -84
- data/lib/inertia_rails/lazy.rb +0 -28
@@ -0,0 +1,130 @@
|
|
1
|
+
import { useForm <%= ', InertiaFormProps ' if inertia_js_version.release == Gem::Version.new('1.3.0') %>} from '@inertiajs/react'
|
2
|
+
import { FormEvent } from 'react'
|
3
|
+
import { <%= inertia_model_form_type %>, <%= inertia_model_type %> } from './types'
|
4
|
+
<% if inertia_js_version.release != Gem::Version.new('1.3.0') %>
|
5
|
+
// Temporary fix for InertiaFormProps not being exported from @inertiajs/react
|
6
|
+
type InertiaFormProps<TForm extends Record<string, any>> = ReturnType<typeof useForm<TForm>>
|
7
|
+
<% end %>
|
8
|
+
interface FormProps {
|
9
|
+
<%= singular_table_name %>: <%= inertia_model_type %>
|
10
|
+
onSubmit: (form: InertiaFormProps<<%= inertia_model_form_type %>>) => void
|
11
|
+
submitText: string
|
12
|
+
}
|
13
|
+
|
14
|
+
export default function Form({ <%= singular_table_name %>, onSubmit, submitText }: FormProps) {
|
15
|
+
const form = useForm<<%= inertia_model_form_type %>>({
|
16
|
+
<% attributes.reject { |a| a.attachment? || a.attachments? }.each do |attribute| -%>
|
17
|
+
<% if attribute.password_digest? -%>
|
18
|
+
password: '',
|
19
|
+
password_confirmation: '',
|
20
|
+
<% else -%>
|
21
|
+
<%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %>,
|
22
|
+
<% end -%>
|
23
|
+
<% end -%>
|
24
|
+
})
|
25
|
+
const { data, setData, errors, processing } = form
|
26
|
+
|
27
|
+
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
|
28
|
+
e.preventDefault()
|
29
|
+
onSubmit(form)
|
30
|
+
}
|
31
|
+
|
32
|
+
return (
|
33
|
+
<form onSubmit={handleSubmit}>
|
34
|
+
<% attributes.each do |attribute| -%>
|
35
|
+
<% if attribute.password_digest? -%>
|
36
|
+
<div>
|
37
|
+
<label style={{ display: 'block' }} htmlFor="password">
|
38
|
+
Password
|
39
|
+
</label>
|
40
|
+
<input
|
41
|
+
type="password"
|
42
|
+
name="password"
|
43
|
+
id="password"
|
44
|
+
onChange={(e) => setData('password', e.target.value)}
|
45
|
+
/>
|
46
|
+
{errors.password && (
|
47
|
+
<div style={{ color: 'red' }}>{errors.password}</div>
|
48
|
+
)}
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div>
|
52
|
+
<label style={{ display: 'block' }} htmlFor="password_confirmation">
|
53
|
+
Password confirmation
|
54
|
+
</label>
|
55
|
+
<input
|
56
|
+
type="password"
|
57
|
+
name="password_confirmation"
|
58
|
+
id="password_confirmation"
|
59
|
+
onChange={(e) => setData('password_confirmation', e.target.value)}
|
60
|
+
/>
|
61
|
+
{errors.password_confirmation && (
|
62
|
+
<div style={{ color: 'red' }}>{errors.password_confirmation}</div>
|
63
|
+
)}
|
64
|
+
</div>
|
65
|
+
<% else -%>
|
66
|
+
<div>
|
67
|
+
<label style={{ display: 'block' }} htmlFor="<%= attribute.singular_name %>">
|
68
|
+
<%= attribute.human_name %>
|
69
|
+
</label>
|
70
|
+
<% if input_type(attribute) == "text_area" -%>
|
71
|
+
<textarea
|
72
|
+
name="<%= attribute.singular_name %>"
|
73
|
+
id="<%= attribute.singular_name %>"
|
74
|
+
value={data.<%= attribute.column_name %>}
|
75
|
+
onChange={(e) => setData('<%= attribute.column_name %>', e.target.value)}
|
76
|
+
/>
|
77
|
+
<% elsif attribute.attachment? -%>
|
78
|
+
<input
|
79
|
+
type="file"
|
80
|
+
name="<%= attribute.singular_name %>"
|
81
|
+
id="<%= attribute.singular_name %>"
|
82
|
+
onChange={(e) => setData('<%= attribute.column_name %>', (e.target.files || [])[0])}
|
83
|
+
/>
|
84
|
+
<% elsif attribute.attachments? -%>
|
85
|
+
<input
|
86
|
+
type="file"
|
87
|
+
multiple
|
88
|
+
name="<%= attribute.singular_name %>[]"
|
89
|
+
id="<%= attribute.singular_name %>"
|
90
|
+
onChange={(e) => setData('<%= attribute.column_name %>', Array.from(e.target.files || []))}
|
91
|
+
/>
|
92
|
+
<% elsif input_type(attribute) == "checkbox" -%>
|
93
|
+
<input
|
94
|
+
type="<%= input_type(attribute) %>"
|
95
|
+
name="<%= attribute.singular_name %>"
|
96
|
+
id="<%= attribute.singular_name %>"
|
97
|
+
checked={data.<%= attribute.column_name %>}
|
98
|
+
onChange={(e) => setData('<%= attribute.column_name %>', e.target.checked)}
|
99
|
+
/>
|
100
|
+
<% elsif input_type(attribute) == "number" -%>
|
101
|
+
<input
|
102
|
+
type="<%= input_type(attribute) %>"
|
103
|
+
name="<%= attribute.singular_name %>"
|
104
|
+
id="<%= attribute.singular_name %>"
|
105
|
+
value={data.<%= attribute.column_name %>}
|
106
|
+
onChange={(e) => setData('<%= attribute.column_name %>', parseInt(e.target.value))}
|
107
|
+
/>
|
108
|
+
<% else -%>
|
109
|
+
<input
|
110
|
+
type="<%= input_type(attribute) %>"
|
111
|
+
name="<%= attribute.singular_name %>"
|
112
|
+
id="<%= attribute.singular_name %>"
|
113
|
+
value={data.<%= attribute.column_name %>}
|
114
|
+
onChange={(e) => setData('<%= attribute.column_name %>', e.target.value)}
|
115
|
+
/>
|
116
|
+
<% end -%>
|
117
|
+
{errors.<%= attribute.column_name %> && (
|
118
|
+
<div style={{ color: 'red' }}>{errors.<%= attribute.column_name %>}</div>
|
119
|
+
)}
|
120
|
+
</div>
|
121
|
+
<% end -%>
|
122
|
+
<% end -%>
|
123
|
+
<div>
|
124
|
+
<button type="submit" disabled={processing}>
|
125
|
+
{submitText}
|
126
|
+
</button>
|
127
|
+
</div>
|
128
|
+
</form>
|
129
|
+
)
|
130
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { Head, Link } from '@inertiajs/react'
|
2
|
+
import <%= inertia_component_name %> from './<%= inertia_component_name %>'
|
3
|
+
|
4
|
+
export default function Index({ <%= plural_table_name %>, flash }) {
|
5
|
+
return (
|
6
|
+
<>
|
7
|
+
<Head title="<%= human_name.pluralize %>" />
|
8
|
+
|
9
|
+
{flash.notice && <p style={{ color: 'green' }}>{flash.notice}</p>}
|
10
|
+
|
11
|
+
<h1><%= human_name.pluralize %></h1>
|
12
|
+
<div>
|
13
|
+
{<%= plural_table_name %>.map((<%= singular_table_name %>) => (
|
14
|
+
<div key={<%= singular_table_name %>.id}>
|
15
|
+
<<%= inertia_component_name %> <%= singular_table_name %>={<%= singular_table_name %>} />
|
16
|
+
<p>
|
17
|
+
<Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link>
|
18
|
+
</p>
|
19
|
+
</div>
|
20
|
+
))}
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<Link href="<%= js_new_resource_path %>">New <%= human_name.downcase %></Link>
|
24
|
+
</>
|
25
|
+
)
|
26
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { Head, Link } from '@inertiajs/react'
|
2
|
+
import <%= inertia_component_name %> from './<%= inertia_component_name %>'
|
3
|
+
import { <%= inertia_model_type %> } from './types'
|
4
|
+
|
5
|
+
interface IndexProps {
|
6
|
+
<%= plural_table_name %>: <%= inertia_model_type %>[]
|
7
|
+
flash: { notice?: string }
|
8
|
+
}
|
9
|
+
|
10
|
+
export default function Index({ <%= plural_table_name %>, flash }: IndexProps) {
|
11
|
+
return (
|
12
|
+
<>
|
13
|
+
<Head title="<%= human_name.pluralize %>" />
|
14
|
+
|
15
|
+
{flash.notice && <p style={{ color: 'green' }}>{flash.notice}</p>}
|
16
|
+
|
17
|
+
<h1><%= human_name.pluralize %></h1>
|
18
|
+
<div>
|
19
|
+
{<%= plural_table_name %>.map((<%= singular_table_name %>) => (
|
20
|
+
<div key={<%= singular_table_name %>.id}>
|
21
|
+
<<%= inertia_component_name %> <%= singular_table_name %>={<%= singular_table_name %>} />
|
22
|
+
<p>
|
23
|
+
<Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link>
|
24
|
+
</p>
|
25
|
+
</div>
|
26
|
+
))}
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<Link href="<%= js_new_resource_path %>">New <%= human_name.downcase %></Link>
|
30
|
+
</>
|
31
|
+
)
|
32
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { Head, Link } from '@inertiajs/react'
|
2
|
+
import Form from './Form'
|
3
|
+
|
4
|
+
export default function New({ <%= singular_table_name %> }) {
|
5
|
+
return (
|
6
|
+
<>
|
7
|
+
<Head title="New <%= human_name.downcase %>" />
|
8
|
+
|
9
|
+
<h1>New <%= human_name.downcase %></h1>
|
10
|
+
|
11
|
+
<Form
|
12
|
+
<%= singular_table_name %>={<%= singular_table_name %>}
|
13
|
+
onSubmit={(form) => {
|
14
|
+
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
15
|
+
form.post('<%= js_resources_path %>')
|
16
|
+
}}
|
17
|
+
submitText="Create <%= human_name %>"
|
18
|
+
/>
|
19
|
+
|
20
|
+
<br />
|
21
|
+
|
22
|
+
<div>
|
23
|
+
<Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
|
24
|
+
</div>
|
25
|
+
</>
|
26
|
+
)
|
27
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { Head, Link } from '@inertiajs/react'
|
2
|
+
import Form from './Form'
|
3
|
+
import { <%= inertia_model_type %> } from './types'
|
4
|
+
|
5
|
+
interface NewProps {
|
6
|
+
<%= singular_table_name %>: <%= inertia_model_type %>
|
7
|
+
}
|
8
|
+
|
9
|
+
export default function New({ <%= singular_table_name %> }: NewProps) {
|
10
|
+
return (
|
11
|
+
<>
|
12
|
+
<Head title="New <%= human_name.downcase %>" />
|
13
|
+
|
14
|
+
<h1>New <%= human_name.downcase %></h1>
|
15
|
+
|
16
|
+
<Form
|
17
|
+
<%= singular_table_name %>={<%= singular_table_name %>}
|
18
|
+
onSubmit={(form) => {
|
19
|
+
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
20
|
+
form.post('<%= js_resources_path %>')
|
21
|
+
}}
|
22
|
+
submitText="Create <%= human_name %>"
|
23
|
+
/>
|
24
|
+
|
25
|
+
<br />
|
26
|
+
|
27
|
+
<div>
|
28
|
+
<Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
|
29
|
+
</div>
|
30
|
+
</>
|
31
|
+
)
|
32
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
export default function <%= inertia_component_name %>({ <%= singular_table_name %> }) {
|
2
|
+
return (
|
3
|
+
<div>
|
4
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
5
|
+
<p>
|
6
|
+
<strong><%= attribute.human_name %>:</strong>
|
7
|
+
<% if attribute.attachment? -%>
|
8
|
+
{<%= singular_table_name %>.<%= attribute.column_name %> && (
|
9
|
+
<a href={<%= singular_table_name %>.<%= attribute.column_name %>.url}>{<%= singular_table_name %>.<%= attribute.column_name %>.filename}</a>
|
10
|
+
)}
|
11
|
+
</p>
|
12
|
+
<% elsif attribute.attachments? -%>
|
13
|
+
</p>
|
14
|
+
{<%= singular_table_name %>.<%= attribute.column_name %>.map((file, i) => (
|
15
|
+
<div key={i}>
|
16
|
+
<a href={file.url}>{file.filename}</a>
|
17
|
+
</div>
|
18
|
+
))}
|
19
|
+
<% else -%>
|
20
|
+
{<%= singular_table_name %>.<%= attribute.column_name %>?.toString()}
|
21
|
+
</p>
|
22
|
+
<% end -%>
|
23
|
+
<% end -%>
|
24
|
+
</div>
|
25
|
+
)
|
26
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { <%= inertia_model_type %> } from './types'
|
2
|
+
|
3
|
+
interface <%= inertia_component_name %>Props {
|
4
|
+
<%= singular_table_name %>: <%= inertia_model_type %>
|
5
|
+
}
|
6
|
+
|
7
|
+
export default function <%= inertia_component_name %>({ <%= singular_table_name %> }: <%= inertia_component_name %>Props) {
|
8
|
+
return (
|
9
|
+
<div>
|
10
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
11
|
+
<p>
|
12
|
+
<strong><%= attribute.human_name %>:</strong>
|
13
|
+
<% if attribute.attachment? -%>
|
14
|
+
{<%= singular_table_name %>.<%= attribute.column_name %> && (
|
15
|
+
<a href={<%= singular_table_name %>.<%= attribute.column_name %>.url}>{<%= singular_table_name %>.<%= attribute.column_name %>.filename}</a>
|
16
|
+
)}
|
17
|
+
</p>
|
18
|
+
<% elsif attribute.attachments? -%>
|
19
|
+
</p>
|
20
|
+
{<%= singular_table_name %>.<%= attribute.column_name %>.map((file, i) => (
|
21
|
+
<div key={i}>
|
22
|
+
<a href={file.url}>{file.filename}</a>
|
23
|
+
</div>
|
24
|
+
))}
|
25
|
+
<% else -%>
|
26
|
+
{<%= singular_table_name %>.<%= attribute.column_name %>?.toString()}
|
27
|
+
</p>
|
28
|
+
<% end -%>
|
29
|
+
<% end -%>
|
30
|
+
</div>
|
31
|
+
)
|
32
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { Head, Link } from '@inertiajs/react'
|
2
|
+
import <%= inertia_component_name %> from './<%= inertia_component_name %>'
|
3
|
+
|
4
|
+
export default function Show({ <%= singular_table_name %>, flash }) {
|
5
|
+
return (
|
6
|
+
<>
|
7
|
+
<Head title={`<%= human_name %> #${<%= singular_table_name %>.id}`} />
|
8
|
+
|
9
|
+
{flash.notice && <p style={{ color: 'green' }}>{flash.notice}</p>}
|
10
|
+
|
11
|
+
<h1><%= human_name %> #{<%= singular_table_name %>.id}</h1>
|
12
|
+
|
13
|
+
<<%= inertia_component_name %> <%= singular_table_name %>={<%= singular_table_name %>} />
|
14
|
+
|
15
|
+
<div>
|
16
|
+
<Link href={`<%= js_edit_resource_path %>`}>Edit this <%= human_name.downcase %></Link>
|
17
|
+
{' | '}
|
18
|
+
<Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
|
19
|
+
|
20
|
+
<br />
|
21
|
+
|
22
|
+
<Link
|
23
|
+
href={`<%= js_resource_path %>`}
|
24
|
+
as="button"
|
25
|
+
method="delete"
|
26
|
+
>
|
27
|
+
Destroy this <%= human_name.downcase %>
|
28
|
+
</Link>
|
29
|
+
</div>
|
30
|
+
</>
|
31
|
+
)
|
32
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { Head, Link } from '@inertiajs/react'
|
2
|
+
import <%= inertia_component_name %> from './<%= inertia_component_name %>'
|
3
|
+
import { <%= inertia_model_type %> } from './types'
|
4
|
+
|
5
|
+
interface ShowProps {
|
6
|
+
<%= singular_table_name %>: <%= inertia_model_type %>
|
7
|
+
flash: { notice?: string }
|
8
|
+
}
|
9
|
+
|
10
|
+
export default function Show({ <%= singular_table_name %>, flash }: ShowProps) {
|
11
|
+
return (
|
12
|
+
<>
|
13
|
+
<Head title={`<%= human_name %> #${<%= singular_table_name %>.id}`} />
|
14
|
+
|
15
|
+
{flash.notice && <p style={{ color: 'green' }}>{flash.notice}</p>}
|
16
|
+
|
17
|
+
<h1><%= human_name %> #{<%= singular_table_name %>.id}</h1>
|
18
|
+
|
19
|
+
<<%= inertia_component_name %> <%= singular_table_name %>={<%= singular_table_name %>} />
|
20
|
+
|
21
|
+
<div>
|
22
|
+
<Link href={`<%= js_edit_resource_path %>`}>Edit this <%= human_name.downcase %></Link>
|
23
|
+
{' | '}
|
24
|
+
<Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
|
25
|
+
|
26
|
+
<br />
|
27
|
+
|
28
|
+
<Link
|
29
|
+
href={`<%= js_resource_path %>`}
|
30
|
+
as="button"
|
31
|
+
method="delete"
|
32
|
+
>
|
33
|
+
Destroy this <%= human_name.downcase %>
|
34
|
+
</Link>
|
35
|
+
</div>
|
36
|
+
</>
|
37
|
+
)
|
38
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export interface <%= inertia_model_type %> {
|
2
|
+
id: number
|
3
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
4
|
+
<%= attribute.column_name %>: <%= ts_type(attribute) %>
|
5
|
+
<% end -%>
|
6
|
+
}
|
7
|
+
|
8
|
+
export type <%= inertia_model_form_type %> = Omit<<%= inertia_model_type %>, <%= omit_input_attributes.map { |a| "'#{a}'" }.join(' | ') %>><% if custom_form_attributes.any? -%> & {
|
9
|
+
<% custom_form_attributes.map do |attribute| -%>
|
10
|
+
<% if attribute.password_digest? -%>
|
11
|
+
password: string
|
12
|
+
password_confirmation: string
|
13
|
+
<% elsif attribute.attachment? -%>
|
14
|
+
<%= attribute.column_name %>?: File
|
15
|
+
<% elsif attribute.attachments? -%>
|
16
|
+
<%= attribute.column_name %>?: File[]
|
17
|
+
<% end -%>
|
18
|
+
<% end -%>
|
19
|
+
}<% end %>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<script>
|
2
|
+
import { Link } from '@inertiajs/svelte'
|
3
|
+
import Form from './Form.svelte'
|
4
|
+
|
5
|
+
let { <%= singular_table_name %> } = $props()
|
6
|
+
|
7
|
+
const handleSubmit = ({ form }) => {
|
8
|
+
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
9
|
+
<% if attributes.any?(&:attachments?) -%>
|
10
|
+
form.post(`<%= js_resource_path %>`, {
|
11
|
+
headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
|
12
|
+
})
|
13
|
+
<% else -%>
|
14
|
+
form.patch(`<%= js_resource_path %>`)
|
15
|
+
<% end -%>
|
16
|
+
}
|
17
|
+
</script>
|
18
|
+
|
19
|
+
<svelte:head>
|
20
|
+
<title>Editing <%= human_name.downcase %></title>
|
21
|
+
</svelte:head>
|
22
|
+
|
23
|
+
<h1>Editing <%= human_name.downcase %></h1>
|
24
|
+
|
25
|
+
<Form
|
26
|
+
{<%= singular_table_name %>}
|
27
|
+
submitText="Update <%= human_name %>"
|
28
|
+
onSubmit={handleSubmit}
|
29
|
+
/>
|
30
|
+
|
31
|
+
<br />
|
32
|
+
|
33
|
+
<div>
|
34
|
+
<Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link> |
|
35
|
+
<Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
|
36
|
+
</div>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<script lang="ts">
|
2
|
+
import { Link, type InertiaFormProps } from '@inertiajs/svelte'
|
3
|
+
import type { <%= inertia_model_type %>, <%= inertia_model_form_type %> } from './types'
|
4
|
+
import Form from './Form.svelte'
|
5
|
+
|
6
|
+
let { <%= singular_table_name %> } = $props<{ <%= singular_table_name %>: <%= inertia_model_type %> }>()
|
7
|
+
|
8
|
+
const handleSubmit = ({ form }: { form: InertiaFormProps<<%= inertia_model_form_type %>> }) => {
|
9
|
+
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
10
|
+
<% if attributes.any?(&:attachments?) -%>
|
11
|
+
form.post(`<%= js_resource_path %>`, {
|
12
|
+
headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
|
13
|
+
})
|
14
|
+
<% else -%>
|
15
|
+
form.patch(`<%= js_resource_path %>`)
|
16
|
+
<% end -%>
|
17
|
+
}
|
18
|
+
</script>
|
19
|
+
|
20
|
+
<svelte:head>
|
21
|
+
<title>Editing <%= human_name.downcase %></title>
|
22
|
+
</svelte:head>
|
23
|
+
|
24
|
+
<h1>Editing <%= human_name.downcase %></h1>
|
25
|
+
|
26
|
+
<Form
|
27
|
+
{<%= singular_table_name %>}
|
28
|
+
submitText="Update <%= human_name %>"
|
29
|
+
onSubmit={handleSubmit}
|
30
|
+
/>
|
31
|
+
|
32
|
+
<br />
|
33
|
+
|
34
|
+
<div>
|
35
|
+
<Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link> |
|
36
|
+
<Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
|
37
|
+
</div>
|
@@ -0,0 +1,97 @@
|
|
1
|
+
<script>
|
2
|
+
import { useForm } from '@inertiajs/svelte'
|
3
|
+
|
4
|
+
let { <%= singular_table_name %>, submitText, onSubmit } = $props()
|
5
|
+
|
6
|
+
const form = useForm({
|
7
|
+
<% attributes.each do |attribute| -%>
|
8
|
+
<% if attribute.password_digest? -%>
|
9
|
+
password: '',
|
10
|
+
password_confirmation: '',
|
11
|
+
<% else -%>
|
12
|
+
<%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %> || <%= default_value(attribute) %>,
|
13
|
+
<% end -%>
|
14
|
+
<% end -%>
|
15
|
+
})
|
16
|
+
|
17
|
+
const handleSubmit = (e) => {
|
18
|
+
e.preventDefault()
|
19
|
+
onSubmit({ form: $form })
|
20
|
+
}
|
21
|
+
</script>
|
22
|
+
|
23
|
+
<form onsubmit={handleSubmit}>
|
24
|
+
<% attributes.each do |attribute| -%>
|
25
|
+
<% if attribute.password_digest? -%>
|
26
|
+
<div>
|
27
|
+
<label for="password">Password</label>
|
28
|
+
<input
|
29
|
+
type="password"
|
30
|
+
name="password"
|
31
|
+
id="password"
|
32
|
+
bind:value={$form.password}
|
33
|
+
/>
|
34
|
+
{#if $form.errors.password}
|
35
|
+
<div class="error">{$form.errors.password.join(', ')}</div>
|
36
|
+
{/if}
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div>
|
40
|
+
<label for="password_confirmation">Password confirmation</label>
|
41
|
+
<input
|
42
|
+
type="password"
|
43
|
+
name="password_confirmation"
|
44
|
+
id="password_confirmation"
|
45
|
+
bind:value={$form.password_confirmation}
|
46
|
+
/>
|
47
|
+
{#if $form.errors.password_confirmation}
|
48
|
+
<div class="error">{$form.errors.password_confirmation.join(', ')}</div>
|
49
|
+
{/if}
|
50
|
+
</div>
|
51
|
+
<% else -%>
|
52
|
+
<div>
|
53
|
+
<label for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
|
54
|
+
<% if input_type(attribute) == "text_area" -%>
|
55
|
+
<textarea name="<%= attribute.singular_name %>" id="<%= attribute.singular_name %>" bind:value={$form.<%= attribute.column_name %>}></textarea>
|
56
|
+
<% elsif attribute.attachment? -%>
|
57
|
+
<input
|
58
|
+
type="file"
|
59
|
+
name="<%= attribute.singular_name %>"
|
60
|
+
id="<%= attribute.singular_name %>"
|
61
|
+
oninput={(e) => ($form.<%= attribute.column_name %> = e.target.files[0])}
|
62
|
+
/>
|
63
|
+
<% elsif attribute.attachments? -%>
|
64
|
+
<input
|
65
|
+
type="file"
|
66
|
+
multiple
|
67
|
+
name="<%= attribute.singular_name %>[]"
|
68
|
+
id="<%= attribute.singular_name %>"
|
69
|
+
oninput={(e) => ($form.<%= attribute.column_name %> = Array.from(e.target.files))}
|
70
|
+
/>
|
71
|
+
<% else -%>
|
72
|
+
<input
|
73
|
+
type="<%= input_type(attribute) %>"
|
74
|
+
name="<%= attribute.singular_name %>"
|
75
|
+
id="<%= attribute.singular_name %>"
|
76
|
+
<%= input_type(attribute) == "checkbox" ? "bind:checked" : "bind:value" %>={$form.<%= attribute.column_name %>}
|
77
|
+
/>
|
78
|
+
<% end -%>
|
79
|
+
{#if $form.errors.<%= attribute.column_name %>}
|
80
|
+
<div class="error">{$form.errors.<%= attribute.column_name %>.join(', ')}</div>
|
81
|
+
{/if}
|
82
|
+
</div>
|
83
|
+
<% end -%>
|
84
|
+
<% end -%>
|
85
|
+
<div>
|
86
|
+
<button type="submit" disabled={$form.processing}>{submitText}</button>
|
87
|
+
</div>
|
88
|
+
</form>
|
89
|
+
|
90
|
+
<style>
|
91
|
+
label {
|
92
|
+
display: block;
|
93
|
+
}
|
94
|
+
.error {
|
95
|
+
color: red;
|
96
|
+
}
|
97
|
+
</style>
|
@@ -0,0 +1,102 @@
|
|
1
|
+
<script lang="ts">
|
2
|
+
import { useForm, type InertiaFormProps } from '@inertiajs/svelte'
|
3
|
+
import type { <%= inertia_model_type %>, <%= inertia_model_form_type %> } from './types'
|
4
|
+
|
5
|
+
let { <%= singular_table_name %>, submitText, onSubmit } = $props<{
|
6
|
+
<%= singular_table_name %>: <%= inertia_model_type %>
|
7
|
+
onSubmit: (props: { form: InertiaFormProps<<%= inertia_model_form_type %>> }) => void
|
8
|
+
submitText: string
|
9
|
+
}>()
|
10
|
+
|
11
|
+
const form = useForm<<%= inertia_model_form_type %>>({
|
12
|
+
<% attributes.reject { |a| a.attachment? || a.attachments? }.each do |attribute| -%>
|
13
|
+
<% if attribute.password_digest? -%>
|
14
|
+
password: '',
|
15
|
+
password_confirmation: '',
|
16
|
+
<% else -%>
|
17
|
+
<%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %> || <%= default_value(attribute) %>,
|
18
|
+
<% end -%>
|
19
|
+
<% end -%>
|
20
|
+
})
|
21
|
+
|
22
|
+
const handleSubmit = (e: SubmitEvent) => {
|
23
|
+
e.preventDefault()
|
24
|
+
onSubmit({ form: $form })
|
25
|
+
}
|
26
|
+
</script>
|
27
|
+
|
28
|
+
<form onsubmit={handleSubmit}>
|
29
|
+
<% attributes.each do |attribute| -%>
|
30
|
+
<% if attribute.password_digest? -%>
|
31
|
+
<div>
|
32
|
+
<label for="password">Password</label>
|
33
|
+
<input
|
34
|
+
type="password"
|
35
|
+
name="password"
|
36
|
+
id="password"
|
37
|
+
bind:value={$form.password}
|
38
|
+
/>
|
39
|
+
{#if $form.errors.password}
|
40
|
+
<div class="error">{$form.errors.password}</div>
|
41
|
+
{/if}
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div>
|
45
|
+
<label for="password_confirmation">Password confirmation</label>
|
46
|
+
<input
|
47
|
+
type="password"
|
48
|
+
name="password_confirmation"
|
49
|
+
id="password_confirmation"
|
50
|
+
bind:value={$form.password_confirmation}
|
51
|
+
/>
|
52
|
+
{#if $form.errors.password_confirmation}
|
53
|
+
<div class="error">{$form.errors.password_confirmation}</div>
|
54
|
+
{/if}
|
55
|
+
</div>
|
56
|
+
<% else -%>
|
57
|
+
<div>
|
58
|
+
<label for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
|
59
|
+
<% if input_type(attribute) == "text_area" -%>
|
60
|
+
<textarea name="<%= attribute.singular_name %>" id="<%= attribute.singular_name %>" bind:value={$form.<%= attribute.column_name %>}></textarea>
|
61
|
+
<% elsif attribute.attachment? -%>
|
62
|
+
<input
|
63
|
+
type="file"
|
64
|
+
name="<%= attribute.singular_name %>"
|
65
|
+
id="<%= attribute.singular_name %>"
|
66
|
+
oninput={(e) => ($form.<%= attribute.column_name %> = ((e.target as HTMLInputElement).files || [])[0])}
|
67
|
+
/>
|
68
|
+
<% elsif attribute.attachments? -%>
|
69
|
+
<input
|
70
|
+
type="file"
|
71
|
+
multiple
|
72
|
+
name="<%= attribute.singular_name %>[]"
|
73
|
+
id="<%= attribute.singular_name %>"
|
74
|
+
oninput={(e) => ($form.<%= attribute.column_name %> = Array.from((e.target as HTMLInputElement).files || []))}
|
75
|
+
/>
|
76
|
+
<% else -%>
|
77
|
+
<input
|
78
|
+
type="<%= input_type(attribute) %>"
|
79
|
+
name="<%= attribute.singular_name %>"
|
80
|
+
id="<%= attribute.singular_name %>"
|
81
|
+
<%= input_type(attribute) == "checkbox" ? "bind:checked" : "bind:value" %>={$form.<%= attribute.column_name %>}
|
82
|
+
/>
|
83
|
+
<% end -%>
|
84
|
+
{#if $form.errors.<%= attribute.column_name %>}
|
85
|
+
<div class="error">{$form.errors.<%= attribute.column_name %>}</div>
|
86
|
+
{/if}
|
87
|
+
</div>
|
88
|
+
<% end -%>
|
89
|
+
<% end -%>
|
90
|
+
<div>
|
91
|
+
<button type="submit" disabled={$form.processing}>{submitText}</button>
|
92
|
+
</div>
|
93
|
+
</form>
|
94
|
+
|
95
|
+
<style>
|
96
|
+
label {
|
97
|
+
display: block;
|
98
|
+
}
|
99
|
+
.error {
|
100
|
+
color: red;
|
101
|
+
}
|
102
|
+
</style>
|