jquense / react-formal

Sophisticated HTML form management for React
http://jquense.github.io/react-formal
MIT License
526 stars 52 forks source link

Disabled submit button until first form interaction #98

Open rosskevin opened 8 years ago

rosskevin commented 8 years ago

I am using the code from #71 to disable the submit button:

import React from 'react';
import Form from 'react-formal';

export function SubmitButton(props) {
  return (
    <Form.Trigger group="@all">
      {({ messages }) =>
         <Form.Button
             {...props}
             type='submit'
             disabled={!!Object.keys(messages).length}
         />
      }
    </Form.Trigger>
  );
}

This works, but it's a bit disruptive from a user experience:

The form is in an invalid state to start with, but given the connections to information (messages is empty initially), I'm unsure of that in the isolated scope of the button. I could render initial disabled then yield to the code above, but other page items could trigger another render making this a naive implementation.

What would be the recommended way to solve this? Preferably I'd like to initially disable the button and listen to the form for the first validation or field blur then yield to the code above.

Any thoughts?