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

Sign up form validation not working with "required" formField #6885

Closed
borisdayma opened this issue Sep 28, 2020 · 12 comments
Closed

Sign up form validation not working with "required" formField #6885

borisdayma opened this issue Sep 28, 2020 · 12 comments
Assignees
Labels
needs-discussion Used for internal discussions UI Related to UI Components

Comments

@borisdayma
Copy link
Contributor

Describe the bug

In the sign up form, "required" fields are only considered for email, username and password.
The form does not catch any incomplete fields that have been set to "required".

To Reproduce
Steps to reproduce the behavior:

In Vue, create a sign up form from <amplify-sign-up> component and add some required formFields.
Then you can still sign-up without filling in those required fields.

Expected behavior
We should get a notification mentioning that those fields are required

Code Snippet

<template>
  <amplify-authenticator username-alias="email">
    <amplify-sign-up
      slot="sign-up"
      username-alias="email"
      :form-fields.prop="formFields"
    />
  </amplify-authenticator>
</template>

<script>
export default {
  data() {
    return {
      formFields: [
        {
          type: 'email',
          required: true,
        },
        {
          type: 'given_name',
          label: 'First Name *',
          placeholder: 'Enter your first name',
          required: true,
        },
        {
          type: 'password',
          required: true,
        },
        {
          type: 'phone_number',
          required: true,
        },
      ],
    }
  },
}
</script>

Screenshots

We can create an account without filling in "First name" and "Phone Number", which are required fields.

image

Once, I got a message saying that given_name was required but it never happened again…

Additional information

I see there is a validationData parameter which appears to be empty.
I assume it should be completed based on these required parameters.
It would be nice to also explain how to use it for more complex scenarios.

@borisdayma borisdayma added the to-be-reproduced Used in order for Amplify to reproduce said issue label Sep 28, 2020
@amhinson
Copy link
Contributor

@borisdayma Could you also share what version of the Amplify packages you are using?

@borisdayma
Copy link
Contributor Author

I use:
@aws-amplify/ui v2.0.2
aws-amplify v3.3.1

@sammartinez sammartinez added needs-discussion Used for internal discussions and removed to-be-reproduced Used in order for Amplify to reproduce said issue labels Nov 16, 2020
@sammartinez
Copy link
Contributor

@borisdayma Thanks for reporting this, in checking the code, I am seeing this as a miss on our side and we need to further step up validation for fields besides phone number, email, and password as you have called out. I do want to call out that we are busy with other priorities within the library and may not get to this for a little bit of time. However, if you are up for it, we would accept a contribution from you if this is something you are want to work on if you have time yourself. Thanks ahead of time!

@ericclemmons
Copy link
Contributor

Here are the two places that could have required added:

<amplify-input
fieldId={this.fieldId}
description={this.description}
type={this.type}
handleInputChange={this.handleInputChange}
placeholder={this.placeholder}
name={this.name}
value={this.value}
inputProps={this.inputProps}
disabled={this.disabled}
/>

<input
id={this.fieldId}
aria-describedby={this.fieldId && this.description ? `${this.fieldId}-description` : null}
type={this.type}
onInput={event => this.handleInputChange(event)}
placeholder={this.placeholder}
name={this.name}
class="input"
value={this.value}
disabled={this.disabled}
{...this.inputProps}
/>

If it's passed along there, these inputs should automatically get HTML5 required validation!

@krikork
Copy link

krikork commented Dec 10, 2020

I recently migrated to @aws-amplify/ui-react from aws-amplify-react so I can leverage the support for SSR with nextjs and am struggling with the same issue.

@mattschutt
Copy link

This is also happening on the React reset password screen. I had to do a lot of customization and copying code out of the library to be able to simply send down the 'name' field. I would love to just tell it to render the require fields and handle it.

Looks like this happened in the Angular library as well: #5636

@ironspur5
Copy link

Any updated on enforcing the required flag? I have custom attributes defined in form fields on sign up, and have set them to be required. Yet, I am able to sign up without them, still.

@jstilesm
Copy link

jstilesm commented May 12, 2021

Still running into this issue where adding required: true below does not throw an error when the field is not filled out.

Currently in my App, only username and password are required for the form.

Relevant Code

const renderSignIn = (
      <>
        {alertMessage && (<div className="customToast">{alertMessage}</div>)}
        <AmplifyAuthenticator
          usernameAlias="username"
          headerText="Sign in or create an account"
          hideToast
        >
          <AmplifySignUp
            headerText="Create account"

            slot="sign-up"
            formFields={[
              { type: 'username', required: true },
              { type: 'password'},
              { type: 'phone_number', required: true},
              { type: 'email', required: true }

            ]}
          />
          <AmplifySignIn slot="sign-in" usernameAlias="username" />
          <AmplifyConfirmSignUp
            headerText="Please check your text messages for your confirmation code"
          />
        </AmplifyAuthenticator>
      </>
    );

Current Version

  • @aws-amplify/ui-react 1.0.0
  • aws-amplify 4.0.0

@ErikCH ErikCH added UI Related to UI Components and removed Amplify UI Components labels May 19, 2021
@ErikCH ErikCH added this to the Current UI Fixes milestone May 21, 2021
@jo2
Copy link

jo2 commented Jun 1, 2021

@ericclemmons Is there anything new on this issue?

Here are the two places that could have required added:

<amplify-input
fieldId={this.fieldId}
description={this.description}
type={this.type}
handleInputChange={this.handleInputChange}
placeholder={this.placeholder}
name={this.name}
value={this.value}
inputProps={this.inputProps}
disabled={this.disabled}
/>

<input
id={this.fieldId}
aria-describedby={this.fieldId && this.description ? `${this.fieldId}-description` : null}
type={this.type}
onInput={event => this.handleInputChange(event)}
placeholder={this.placeholder}
name={this.name}
class="input"
value={this.value}
disabled={this.disabled}
{...this.inputProps}
/>

If it's passed along there, these inputs should automatically get HTML5 required validation!

As far as I've seen, the required field is not used in

<select
name={this.fieldId}
id={this.fieldId}
class="select"
onChange={this.handleInputChange}
>
{this.selectOptions}
</select>
and
<input
id={this.fieldId}
aria-describedby={
this.fieldId && this.description
? `${this.fieldId}-description`
: null
}
data-autocompleted={this.autoCompleted}
type={this.type}
onInput={event => {
this.autoCompleted = false;
this.handleInputChange(event);
}}
placeholder={this.placeholder}
name={this.name}
class="input"
value={this.value}
disabled={this.disabled}
{...this.inputProps}
/>

I kind of need this feature, so I could submit a PR if you want.

@jacoblogan
Copy link
Contributor

This issue has been reproduced and is being worked on

@eddiekeller
Copy link
Contributor

Merged in PR ^^ to fix the required prop not doing anything on those inputs. I will close this ticket now, but please open it back up or submit a new ticket to us if any issues remain for you!

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-discussion Used for internal discussions UI Related to UI Components
Projects
None yet
Development

No branches or pull requests