Skip to content

About

Javaabu forms implementation in react using onu package.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

50 Commits

Folders and files

Repository files navigation

Forms for React

Tests Coverage npm License

@javaabu/forms is the React version of javaabu/forms, the Laravel Blade form components. It has the same components and attributes, model binding, old input and validation errors, so a form looks and behaves the same in a Blade view and an Inertia React page. It renders with Onu, shadcn/ui, plain HTML or your own UI kit.

<x-forms::form :model="$article" method="PATCH" :action="route('articles.update', $article)">
    <x-forms::text name="title" required />
    <x-forms::select2 name="category" :options="$categories" relation />
    <x-forms::checkbox name="is_featured" />
    <x-forms::submit>Save</x-forms::submit>
</x-forms::form>
import { Checkbox, Form, Select2, Submit, Text } from "@javaabu/forms"
import { update } from "@/actions/App/Http/Controllers/ArticlesController"

;<Form model={article} action={update}>
  <Text name="title" required thaana />
  <Select2 name="category" options={categories} relation />
  <Checkbox name="is_featured" />
  <Submit>Save</Submit>
</Form>

Features

  • The Blade API. The same component names, camelCase attributes, generated ids and translated labels.
  • Laravel built in. Model binding, old input, method spoofing, CSRF, relations, sync_ fields, and validation errors under the right field, including error bags and items.0.name keys.
  • Any UI. Adapters for Onu, shadcn/ui and plain HTML, a typed adapter contract with a conformance test kit, and per-component overrides.
  • Inertia and Wayfinder. Forms submit as Inertia visits, or through useForm(), without glue code, and take Wayfinder routes as action. They also submit natively or with fetch.
  • Dhivehi and RTL. English and Dhivehi strings with @javaabu/i18n, RTL layouts and Thaana typing.

Installation

npm install @javaabu/forms
import { FormsProvider } from "@javaabu/forms"
import { inertia } from "@javaabu/forms/inertia"
import { onu } from "@javaabu/forms/onu"

;<FormsProvider ui={onu} router={inertia}>
  {children}
</FormsProvider>

Without a bundler, load the <script> tag build. It puts the components on window.JavaabuForms, with React bundled in:

<script src="https://unpkg.com/@javaabu/forms/dist/forms.iife.js"></script>
<script>
  const { h, mount, Form, Text, Submit } = JavaabuForms
  mount("#app", h(Form, { action: "/users" }, h(Text, { name: "name" }), h(Submit)))
</script>

See Installation and setup.

Documentation

The full documentation is in docs/, with an index for AI assistants in llms.txt. Start with:

Development

pnpm install
pnpm examples   # one page per adapter (add ?dv for Dhivehi)
pnpm check      # lint, format, typecheck, tests, build, examples

License

The MIT License (MIT). Please see License File for more information.

About

Javaabu forms implementation in react using onu package.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages