Magically create forms + actions in Remix!

Overview

Welcome to Remix Forms!

This repository contains the Remix Forms source code. We're just getting started and the APIs are unstable, so we appreciate your patience as we figure things out.

Documentation

For documentation about Remix Forms, please visit remix-forms.seasoned.cc.

Also, please join Remix's community on Discord. We'll be there to provide you support on Remix Forms.

Comments
  • make react hook forms defaultValues property accessible

    make react hook forms defaultValues property accessible

    I want to use react hook forms defaultValues property like its described here: https://react-hook-form.com/api/useform/

    If the default values are defined this way the dirty field status works even better: If the user changes a fields value from the default value to a new value and then back to the default value, the form is not dirty anymore. Without the defaultValues it would be still dirty.

    This pr also helps to provide default values easier than via zod schema. <Form schema={schema} method="patch" defaultValues={{email: '[email protected]', firstName: 'Mary'}}>

    opened by luckals 11
  • `useFormContext` should be available through children

    `useFormContext` should be available through children

    Since we are using react-hook-form. It would be nice to have access to stuff like isSubmitting from the form children without having to pass it down the three.

    Right now, the form is controlling the label of the button to indicate the form is submiting but if you are working with UI libs like Chakra, you might want to use somethnig like <Button isLoading />

    opened by wladiston 11
  • Custom styles example?

    Custom styles example?

    Can someone point me to how can custom styles be applied? I'm using Tailwind.

    I'm extending the form as per docs but I can't figure out how to add the className to the element

     multilineComponent={"select"} /* your custom Multiline */
    

    Thank you!

    opened by netdesignr 8
  • Wrap fields with context to expose a `useField` hook

    Wrap fields with context to expose a `useField` hook

    This hook can be used in any of the custom components, allowing those to change styling/behavior etc depending on the field's state. This is mostly useful for things like the required/error/dirty indicators (e.g. https://remix-forms.seasoned.cc/examples/render-field/required-indicator) which currently require the use of the renderField prop. See also #124.

    Using the prop makes things quite verbose because the structure of each field will have to be replicated, even if just a single component needs to be customized. Since the default structure is not the same for all field types, customizing components in this way requires some gnarly copy and paste from the package's source code (see https://remix-forms.seasoned.cc/examples/render-field/inline-checkboxes).

    For now, the PR only contains the code required to make useField work. If the maintainers agree with this approach, I'll add some examples to the docs as well (perhaps even replacing the current renderField section?), and tests where applicable.

    opened by bvangraafeiland 7
  • Add multiple forms example

    Add multiple forms example

    Description

    This PR adds an example to illustrate how to use multiple forms on the same route with the same action.

    Notes

    I could not figure out how to make it so only the button on the submitted form goes into a pending state - if anyone has feedback or suggestions on this I'll happily update! 🙏

    Source

    https://twitter.com/seasonedcc/status/1589730417330225153?s=20&t=dN-tDjj0_13Jlv2KkDZDaA

    opened by lewischa 7
  • Remove lodash dependency

    Remove lodash dependency

    As @tavoyne pointed out on #62 , lodash is taking up to 48% of remix-forms' package size (over 67kb 😱).

    I started playing with this PR by using the

    import startCase from 'lodash/startCase'
    

    syntax so it would already reduce the bundle size but ended up completely replacing lodash's startCase with a custom (yet well tested) version of startCase and replacing concat with the native ES6's array spread.

    This way we'll have only 2 dependencies if this PR is merged: react-hook-form and @hookform/resolvers.

    opened by gustavoguichard 7
  • Unable to make checkbox required

    Unable to make checkbox required

    I am trying to make a checkbox required to be true within the zod schema, but the form is still submitting no matter what I have tried so far. There is an example that shows this on the website, but it just sets the default to false. It has a required indicator, but accepts either true or false.

    Is there a way to do this currently?

    opened by jnoahjohnson 7
  • Feature: custom input registration

    Feature: custom input registration

    I think we could improve the DX a bit just by exporting the registered input already as a prop.

    Currently if we want to make a custom input we need to do this:

    <Field name="email">
      {({ Label, Errors }) => (
        <>
          <Label />
          <input
            type="email"
            {...register('email')}
            className="border-2 border-dashed rounded-md"
          />
          <Errors />
        </>
      )}
    </Field>
    

    Since the Field has the name it would make sense to just do this

    <Field name="email">
      {({ Label, Errors, props }) => (
        <>
          <Label />
          <input type="email"  {...props}  className="border-2 border-dashed rounded-md" />
          <Errors />
        </>
      )}
    </Field>
    
    opened by wladiston 7
  • `formAction` successPath not respecting browser history

    `formAction` successPath not respecting browser history

    If you visit the Custom Response example, then click on the Redirect example, and submit the form, you will be redirected to the /success page

    However, if you then click the "Back" button in your browser, you are taken to the Custom Response example (instead of the Redirect example)

    opened by brunocrosier 7
  • Return boolean out of the checkbox

    Return boolean out of the checkbox

    Hi,

    What would be the recommended way to return a boolean value out of the checkbox type input field? At the moment it returns "on" | "off"

    Thanks a lot!

    opened by netdesignr 6
  • Reset form after submit

    Reset form after submit

    Is there any way to reset form after submitted?

    I tried following way but no luck :(

    
    export default function AccountsIndexPage() {
      const data = useLoaderData<LoaderData>();
      let transition =  useTransition();
      let isAdding = transition.state === "submitting";
      let formRef = useRef<HTMLFormElement>(null);
      useEffect(() => {
        if(!isAdding)  {
          formRef.current?.reset();
        }
      }, [isAdding]);
      return (
        <Panel>
          
          <DataTable>
          
            <Form schema={schema} ref={formRef} className="valid-form flex flex-wrap flex-row -mx-4 mb-6" id="account-form">
              {({ Field, Errors, Button, register }) => (
    
              ....
    

    In my console I get following errors:

    react-dom.development.js:86 Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
    
    Check the render method of `AccountsIndexPage`.
        at Form3
        at div
        at div
        at div
        at div
        at div
        at div
        at DataTable (http://localhost:5000/build/_shared/chunk-6HY25IE3.js:878:22)
        at div
        at Panel (http://localhost:5000/build/_shared/chunk-6HY25IE3.js:847:18)
        at AccountsIndexPage (http://localhost:5000/build/routes/dashboard/organization/accounts/index-2NPI7QXN.js:56:16)
        at RemixRoute (http://localhost:5000/build/_shared/chunk-3WT6HRTL.js:2552:3)
        at Outlet (http://localhost:5000/build/_shared/chunk-3WT6HRTL.js:675:26)
    

    Is there any option to automatically reset form after submitted ?

    opened by zolzaya 6
  • Render inputErrors for fields that are not part of the schema as global errors

    Render inputErrors for fields that are not part of the schema as global errors

    Let's say we're updating a user at /users/$userId/edit:

    const formSchema = z.object({
      firstName: z.string().min(1),
      email: z.string().min(1).email(),
    })
    
    const mutationSchema = formSchema.extend({ userId: z.string() })
    
    const mutation = makeDomainFunction(mutationSchema)(async (values) => values)
    
    export const action: ActionFunction = async ({ request, params }) =>
      formAction({
        request,
        schema,
        mutation,
        transformValues: (values) => ({ ...params, ...values }),
      })
    
    export default () => <Form schema={formSchema} />
    

    If for any reason the userId is not present in the params, the mutation will not succeed but formAction will not return an error for the missing userId.

    It would be nice if we could show them as global errors and give feedback to the developer that something is off with the wiring between Form and action. Right now, the form submission will not succeed but no error will be shown.

    I'm looking for a generic way to implement this as a convention in Remix Forms: whenever we have an inputError for a field that's not part of the form schema, we make it a global error.

    opened by danielweinmann 0
  • Make `formAction` return inferrable

    Make `formAction` return inferrable

    Whenever we return the formAction in an action:

    export async function action({ request }: ActionArgs) {
      return formAction( // ...)
    }
    
    export default function() {
      const actionData = useActionData<typeof action>()
      //         ^? any
    }
    

    The useActionData loses the inference - it will be inferred as any.

    It'd be cool that it would infer the TypedResponse for us. The inferred type should probably be a union of:

    { errors: FormErrors<SchemaType>, values: FormValues<SchemaType> } | UnpackData<typeof mutation>
    

    Things to consider:

    • If we use a custom json in createFormAction we should be using the return of that given function
    • If we set a successPath in the formAction the return type of the mutation should not be considered:
    { errors: FormErrors<SchemaType>, values: FormValues<SchemaType> }
    
    opened by gustavoguichard 1
  • And `render` prop to `Form`

    And `render` prop to `Form`

    The render function would receive the same arguments as children + Form (which would be the value of component prop passed either to the form or to createForm) + fetcher (which would be the value of the fetcher prop).

    It would be called whenever there are no children passed to the form, just like renderField is called when there are no children passed to Field.

    That would allow us to customize the default markup of the forms, including custom pending UI like the one described in #37.

    opened by danielweinmann 3
  • Add prop types of custom components

    Add prop types of custom components

    When using the field children, you can pass some props to the Label/Input etc. However, the prop types of the components are JSX.IntrinsicElements['input'] for example, so if you have a custom input component that takes a size prop, you end up with a typescript error.

    In reality the props are being passed through, so it will work if you ignore the type error, but it would be nice if the prop types could be merged somehow.

    opened by bvangraafeiland 3
  • Pass a `Fields` component through Form children

    Pass a `Fields` component through Form children

    This component would:

    • Render all fields in the schema precisely as if we hadn't passed children to the form. This is useful because sometimes we just want to customize the errors, the button, or the overall form layout. But not the fields. In this situation, we're currently forced to render all fields manually.
    • If we pass children to it, we only pass the Fields we want to customize, but it will render all form fields in the same order as the schema. This will allow us to customize only the fields we want and rely on the convention for the rest.

    This should not change the current Form children render logic. It will only add this option to make our forms even DRYer.

    opened by danielweinmann 0
Releases(v1.4.0)
  • v1.4.0(Dec 16, 2022)

    Highlights

    • Wrap fields with context to expose a useField hook by @bvangraafeiland in https://github.com/SeasonedSoftware/remix-forms/pull/133 - Check out the new example.

    What's Changed

    • Fix hook order on Form by @danielweinmann in https://github.com/SeasonedSoftware/remix-forms/pull/129
    • Revalidate (or at least clean) server errors on input change by @diogob in https://github.com/SeasonedSoftware/remix-forms/pull/126
    • Show hidden input errors as global errors by @felipefreitag in https://github.com/SeasonedSoftware/remix-forms/pull/132
    • Add infrastructure for mdx docs by @felipefreitag in https://github.com/SeasonedSoftware/remix-forms/pull/134

    Full Changelog: https://github.com/SeasonedSoftware/remix-forms/compare/v1.3.0...v1.4.0

    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Dec 12, 2022)

    What's Changed

    • Add reValidateMode prop by @felipefreitag in https://github.com/SeasonedSoftware/remix-forms/pull/125
    • Wrap forms with RHF's FormProvider by @bvangraafeiland in https://github.com/SeasonedSoftware/remix-forms/pull/127

    New Contributors

    • @bvangraafeiland made their first contribution in https://github.com/SeasonedSoftware/remix-forms/pull/127

    Full Changelog: https://github.com/SeasonedSoftware/remix-forms/compare/v1.2.2...v1.3.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.2(Dec 7, 2022)

    README updates

    • Update Discord link to our own community by @gustavoguichard in https://github.com/SeasonedSoftware/remix-forms/pull/117
    • Update discord links by @danielweinmann in https://github.com/SeasonedSoftware/remix-forms/pull/118

    Bugfixes

    • Fix several use cases to customize radio buttons by @diogob in https://github.com/SeasonedSoftware/remix-forms/pull/116
    • Fix radio labels when using field with children by @diogob in https://github.com/SeasonedSoftware/remix-forms/pull/120

    Full Changelog: https://github.com/SeasonedSoftware/remix-forms/compare/v1.2.1...v1.2.2

    Source code(tar.gz)
    Source code(zip)
  • v1.2.1(Dec 1, 2022)

    Bug Fix

    • Fix markup for radio buttons and ensure default values are loaded properly by @danielweinmann in https://github.com/SeasonedSoftware/remix-forms/pull/112

    Full Changelog: https://github.com/SeasonedSoftware/remix-forms/compare/v1.2.0...v1.2.1

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Dec 1, 2022)

    New features

    Docs

    New Contributors

    • @lewischa made their first contribution in #104

    Full Changelog: https://github.com/SeasonedSoftware/remix-forms/compare/1.1.0...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Nov 7, 2022)

    New features

    Bug Fix (breaking change)

    • Before this release enums without a default value would be rendered by default as a select component having the first option selected. Now the component will be rendered without any selected option unless specified in the values property.

    Full Changelog: https://github.com/SeasonedSoftware/remix-forms/compare/v1.0.0...1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Nov 1, 2022)

    Allow usage with React Router 6.4 🚀

    Breaking changes

    • You now need to createForm and createFormAction before using Remix Forms. See upgrade instructions below. (#93)
    • The transition argument is not passed to Form's children anymore. If you used to get the transition from the children function, now you need to get it directly from useTransition, useNavigation, or useFetcher. (#93)

    New features

    Upgrade instructions

    If you're using Remix Forms 0.x.x, upgrading is very easy. Here's what you have to do:

    • Create a custom formAction for your project and import it whenever you used to import { formAction } from 'remix-forms'. Follow the instructions on our Get Started guide to create it.
    • If you haven't yet created a custom Form component for your project, create one by following our Get Started guide. Then, import it whenever you used to import { Form } from 'remix-forms'.
    • If you already created a custom Form component, you'll need to do a couple of changes to it. Check out the very last section of our Get Started guide for instructions.
    Source code(tar.gz)
    Source code(zip)
Owner
Seasoned
Enabling non-technical founders
Seasoned
Deploy an Architect project from GitHub Actions with keys gathered from aws-actions/configure-aws-credentials

Deploy an Architect project from GitHub Actions with keys gathered from a specific AWS IAM Role federated by an IAM OIDCProvider. CloudFormation to cr

Taylor Beseda 4 Apr 6, 2022
A Remix Auth strategy for working with forms.

FormStrategy A Remix Auth strategy to work with any form. Supported runtimes Runtime Has Support Node.js ✅ Cloudflare ✅ How to use This Strategy gives

Sergio Xalambrí 40 Jan 2, 2023
simple-remix-blog is a blog template built using Remix and TailwindCSS. Create your own blog in just a few minutes!

simple-remix-blog is a blog template built using remix.run and TailwindCSS. It supports markdown and MDX for the blog posts. You can clone it and star

José Miguel Álvarez Vañó 8 Dec 8, 2022
express-like middleware system for your remix loaders and actions

remix-middleware Add an express-like middleware stack to your remix loaders and actions! yarn add remix-middleware // ./app/middleware.server.ts expor

Eric Bower 26 Nov 22, 2022
Automatically document all of your Remix loaders and actions typings per each route. 📚

About remix-docs-gen parses all of your Remix loaders and actions and automatically documents all the typings per each route. Installation First, you

Stratulat Alexandru 50 Nov 9, 2022
Zod utilities for Remix loaders and actions.

Zodix Zodix is a collection of Zod utilities for Remix loaders and actions. It abstracts the complexity of parsing and validating FormData and URLSear

Riley Tomasek 172 Dec 22, 2022
The Remix version of the fakebooks app demonstrated on https://remix.run. Check out the CRA version: https://github.com/kentcdodds/fakebooks-cra

Remix Fakebooks App This is a (very) simple implementation of the fakebooks mock app demonstrated on remix.run. There is no database, but there is an

Kent C. Dodds 61 Dec 22, 2022
Remix Stack for deploying to Vercel with remix-auth, Planetscale, Radix UI, TailwindCSS, formatting, linting etc. Written in Typescript.

Remix Synthwave Stack Learn more about Remix Stacks. npx create-remix --template ilangorajagopal/synthwave-stack What's in the stack Vercel deploymen

Ilango 56 Dec 25, 2022
Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. In this workshop, we'll look at some more advanced use cases when building Remix applications.

?? Advanced Remix Workshop Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. In this

Frontend Masters 167 Dec 9, 2022
Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. Get a jumpstart on Remix with this workshop.

?? Remix Fundamentals Build Better websites with Remix Remix enables you to build fantastic user experiences for the web and feel happy with the code

Frontend Masters 204 Dec 25, 2022
PaperFreeForm is a Free Form Builder to save trees and create beautiful forms

PaperFreeForm PaperFreeForm is a Free Form Builder to save trees and create beautiful forms. Easy online form builder that works like a doc. Just add

Zaid Mukaddam 5 Feb 24, 2022
Create a badge using GitHub Actions and GitHub Workflow CPU time

Generated Badges Create a badge using GitHub Actions and GitHub Workflow CPU time (no 3rd parties servers) Install $ npm i generated-badges -g Command

小弟调调™ 9 Dec 30, 2022
Create deployment files and configure GitHub Actions workflows to deploy applications to Azure Kubernetes Service (AKS).

Azure Kubernetes Service (AKS) DevX (Developer experience) Extension for Visual Studio Code (Preview) The AKS DevX extension for Visual Studio Code (P

Microsoft Azure 11 Oct 1, 2022
Inventory App - a SPA project developed with Angular using Reactive Forms and VMware's Clarity components.

Inventory App - a SPA (Single Page Application) project developed with Angular using Reactive Forms and VMware's Clarity components.

null 11 Oct 5, 2022
testing out ember + netlify's forms

survey-netlify I'm trying Ember + Netlify Forms. Will it work? Let's find out. Steps so far added prember and ember-cli-fastboot used the version of f

Melanie Sumner 3 Feb 14, 2022
A self-hosted solution for creating/managing forms and applications.

Centox - Self-hosted form website It is a self-hosted solution for creating/managing forms and applications. Users can login using their Discord Accou

Simon Maribo 11 Dec 26, 2022
A jQuery-free general purpose library for building credit card forms, validating inputs and formatting numbers.

A jQuery-free general purpose library for building credit card forms, validating inputs and formatting numbers.

Jesse Pollak 528 Dec 30, 2022
Angular 14 JWT Authentication & Authorization with Web API and HttpOnly Cookie - Token Based Auth, Router, Forms, HttpClient, BootstrapBootstrap

Angular 14 JWT Authentication with Web API and HttpOnly Cookie example Build Angular 14 JWT Authentication & Authorization example with Web Api, HttpO

null 20 Dec 26, 2022
Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.

JSON Form The JSON Form library is a JavaScript client-side library that takes a structured data model defined using JSON Schema as input and returns

null 2.6k Dec 28, 2022