import { useForm } from '@inertiajs/react' export default function Form({ <%= singular_table_name %>, onSubmit, submitText }) { const form = useForm({ <% attributes.each do |attribute| -%> <% if attribute.password_digest? -%> password: '', password_confirmation: '', <% else -%> <%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %> || <%= default_value(attribute) %>, <% end -%> <% end -%> }) const { data, setData, errors, processing } = form const handleSubmit = (e) => { e.preventDefault() onSubmit(form) } return (
<% attributes.each do |attribute| -%>
<% if attribute.password_digest? -%> setData('password', e.target.value)} /> {errors.password && (
{errors.password.join(', ')}
)}
setData('password_confirmation', e.target.value)} /> {errors.password_confirmation && (
{errors.password_confirmation.join(', ')}
)} <% else -%> <% if input_type(attribute) == "text_area" -%>