NUDelta/ce-platform

Require Profile Image on Sign Up

youralien opened this issue · 0 comments

I was struggling with this... so here is a list of things to try for the next time someone tries to fix this issue.

Starting documentation on configuring fields in AccountsTemplates
https://github.com/meteor-useraccounts/core/blob/master/Guide.md#form-fields-configuration

In accounts_config.js

AccountsTemplates.addField({
  _id: 'profileImage',
  type: 'text',
  displayName: 'Profile photo',
  template: 'profileImageUpload',
  // the field value is not set based on profile image upload
  // 1. To see where the validate gets called, @see https://github.com/meteor-useraccounts/core/blob/2e8986813b51f321f908d2f6211f6f81f76cd627/lib/templates_helpers/at_input.js#L98
  // 2. Definition of validate where parameter "value" is passed @see https://github.com/meteor-useraccounts/core/blob/2e8986813b51f321f908d2f6211f6f81f76cd627/lib/field.js#L224
  required: true,
  // somehow, it is hard to enter this func call. Maybe because the "value" is not even set for it to pass the required check
  // @see https://github.com/meteor-useraccounts/core/blob/2e8986813b51f321f908d2f6211f6f81f76cd627/lib/field.js#L274
  func: function(value) {
    let imageFiles = getImageFiles();
    let photoUploaded = imageFiles.length > 0;
    if (photoUploaded) {
      this.setSuccess();
      this.setValidating(false);
      return false;
    } else {
      this.setError(AccountsTemplates.texts.requiredField);
      this.setValidating(false);
      return AccountsTemplates.texts.requiredField
    }
  },
  errStr: 'Profile Image Required'
});