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

User enroll : add extra fields #737

Open
KernelPan1k opened this issue Mar 14, 2017 · 5 comments
Open

User enroll : add extra fields #737

KernelPan1k opened this issue Mar 14, 2017 · 5 comments

Comments

@KernelPan1k
Copy link

Hello,

When I send an invitation to a user, after he is clicked the link received in an email, he is redirected and has to entre his password to finalize his registration. Is it possible to add fields personalized in this form?

Thank you very much to all!

@anschutz
Copy link

For now any custom field will only be shown on sign up state.
However, you can monkey patch the visibility of any field after AccountsTemplates has initialized.
For example:
`Meteor.startup(() => {
const fields = AccountsTemplates.getFields();

for (let i = 0; i < fields.length; i++) {
let field = fields[i];
if (field._id === 'firstname' || field._id === 'lastname') {
// Enable it for any other states you want
field.visible = ['signUp', 'enrollAccount'];
}
}
});`

Call that from a file where you configure the rest of the AccountsTemplates stuff. Meteor.startup() makes sure it's called after initialization.

In order for this to make any difference, you have to configure onSubmitHook, manually get the values of your custom fields and act accordingly.

@KernelPan1k
Copy link
Author

Hello, thank you a lot for this answer. I had in the end chosen to develop a system personalized of invitation of the users, I think that I am going to go back is tested this method.
Thank you very much and excellent end of the week.

@ruzpuz
Copy link

ruzpuz commented Dec 6, 2018

@anschutz Sorry to bump this, but I need a bit help over here.

what would be the right way to handle this in onSubmitHook? I am new to meteor so I would really appreciate a dummy-friendly response

@anschutz
Copy link

@ruzpuz You'll have to set up a method that sets those values and call it from the onSubmitHook. E.g.

onSubmitHook(error, state) {
  // Avoid calling it if something went wrong or if we're submitting some other form.  
  if (error || state !== 'enrollAccount') {
    return;
  }

  const firstnameInput = document.getElementById('at-field-firstname');
  const lastnameInput = document.getElementById('at-field-lastname');

  setFirstLastName.call({
    firstname: firstnameInput.value,
    lastname: lastnameInput.value,
  }, (error) => {
    if (error) {
      console.error(error.reason);
    }
  });
},

@ruzpuz
Copy link

ruzpuz commented Dec 10, 2018 via email

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

3 participants