#✅ - Authenticator formfield add a drop down list with custom cognito attribute.

17 messages · Page 1 of 1 (latest)

little token
#

So I'm building this app with Authenticator pre-built UI component. I'm able to pass my custom cognito attribute with a value of what ever the input text value was to the backend . But I want to have an option in sign up form where instead of input type text. The sign up form would contain a selectField prebuilt UI component who selected value will be map to custom cognito attribute to send to back end. So I can display a user favorite fruit on the front-end. I've posted my code below for reference. Any help would be greatly appreciated.

import { Authenticator } from "@aws-amplify/ui-react";
import "@aws-amplify/ui-react/styles.css";
import { SelectField } from "@aws-amplify/ui-react";

const Login = () => {
const DefaultSelectFieldExample = () => (
<SelectField label="Fruit" descriptiveText="What's your favorite fruit?">
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="orange">Orange</option>
</SelectField>
);

const signUpFields = {
signUp: {
"custom:fruit": {//have this be a drop down list using the selectFieldComponent, with value of a fruit a user selected.
placeholder: "What's your favorite fruit?",
isRequired: true,
label: "Fruit:",
order: 5,
},
email: {
order: 1,
},
username: {
order: 2,
},
password: {
order: 3,
},
confirm_password: {
order: 4,
},
},
};

return (
<Authenticator formFields={signUpFields}>
{({ signOut, user }) => (
<main>
<h1>Hello {user.username}</h1>
<button onClick={signOut}>Sign out</button>
<h2> my favorite fruit is {user.attributes["custom:fruit"]} </h2>//display the value the user selected on sign up for their favorite fruit.
</main>
)}
</Authenticator>
);
};

export default Login;

dawn jay
little token
#

Ah so i need to explictly add this in my authenticator component

<Authenticator
// Default to Sign Up screen
initialState="signUp"
// Customize Authenticator.SignUp.FormFields
components={{
SignUp: {
FormFields() {
const { validationErrors } = useAuthenticator();

        return (
          <>
#

their is no way to add select field component inside customFruit?

const signUpFields = {
signUp: {
"custom:fruit": {//have this be a drop down list using the selectFieldComponent, with value of a fruit a user selected.
placeholder: "What's your favorite fruit?",
isRequired: true,
label: "Fruit:",
order: 5,
},
email: {
order: 1,
},
username: {
order: 2,
},
password: {
order: 3,
},
confirm_password: {
order: 4,
},
},
};

dawn jay
little token
#

ah darn wish it was flexible in its different input types

dawn jay
#

IS there a reason why customizing FormFields component does not work for your usecase? Feel free to open a feature request detailing your usecase here: https://github.com/aws-amplify/amplify-ui/issues

GitHub

Amplify UI is a collection of accessible, themeable, performant React (and more!) components that can connect directly to the cloud. - Issues · aws-amplify/amplify-ui

little token
#

Customizing the formFields does work for my use case. Was just confused on how to pass a custom cognito attribute with a selectField component

dawn jay
#

Please add a feature request and we'll consider implementing it!

#

Or if you feel comfortable, we appreciate contributions!

little token
#

Ah okay yeah I’ll make a feature request .

dawn jay
#

Cool, resolving this thread, we'll track the feature request in gtihub then.

rancid surgeBOT
#

Answer selected!
IS there a reason why customizing FormFields component does not work for your usecase? Feel free to open a feature request detailing your usecase here: https://github.com/aws-amplify/amplify-ui/issues
Kudos to @dawn jay!
#1101275567631896596 message

rancid surgeBOT
#

🤕 Something went wrong

rancid surgeBOT
#

🤕 Something went wrong

vestal dirge
#

Authenticator formfield add a drop down list with custom cognito attribute.

rancid surgeBOT
#

✅ - Authenticator formfield add a drop down list with custom cognito attribute.