Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled submit button until first form interaction #98

Open
rosskevin opened this issue Nov 16, 2016 · 0 comments
Open

Disabled submit button until first form interaction #98

rosskevin opened this issue Nov 16, 2016 · 0 comments

Comments

@rosskevin
Copy link
Contributor

rosskevin commented Nov 16, 2016

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:

  • open the page - submit is enabled
  • start typing invalid information or enter/leave a field - submit is disabled

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant