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

forms load after button clicked #23

Open
jonquixote opened this issue Dec 23, 2014 · 0 comments
Open

forms load after button clicked #23

jonquixote opened this issue Dec 23, 2014 · 0 comments

Comments

@jonquixote
Copy link

i am working on a template to update the user profile. i am using a mixture of simple form and underscore to do this. my forms are updating the right collection (Meteor.user().profile) but they are loading in an odd way.
when a user is first created, the form only shows the update profile button. the rest of the page is empty with the exception of the page title. when i click the button, the forms appear! after this, they are visible to the user permanently. this is odd to me. after the forms appear, they work as they should. what i want is for the forms to appear when the page is loaded!
here is my editprofile template

<form>
  {{#each profileFields}}
    {{> _profileField}}
  {{/each}}
  {{submit_button 'Update Profile'}}
</form>

my _profileField template

{{#if isTextField}}


{{#with editprofile}}
{{text_field ../name type=../type required=../required hint=../hint placeholder=../placeholder afterAddon=../afterAddon class="profileField"}}
{{/with}}

{{/if}}

{{#if isTextArea}}


{{#with editprofile}}
{{text_area ../name type=../type required=../required hint=../hint placeholder=../placeholder afterAddon=../afterAddon class="profileField"}}
{{/with}}

{{/if}}

{{#if isCheckbox}}


{{#with profile}}
{{check_box name label=label required=required}}
{{/with}}

{{/if}}

{{#if isFileField }}


{{> file_field object=profile field=name}}

{{/if}}

here is my editsprofile.js

Template.editprofile.helpers({
profileFields: function() {
return [
{ name: "firstName", required: true },
{ name: "lastName", required: true },
{ name: "location", required: false },
{ name: "bio", required: false, type: 'text_area' },
{ name: "url", required: false },
{ name: "googlePlusUrl", required: false },
{ name: "twitterHandle", required: false }
];
}
});

Template.editprofile.events({
'submit form': function(event) {
event.preventDefault();
var data = SimpleForm.processForm(event.target);
Meteor.users.update(Meteor.userId(), {$set: {profile: data}});
}
});

Template._profileField.helpers({
editprofile: function() {
if (Meteor.user()) {
return Meteor.user().profile;
}
},

isTextField: function() {
return this.type !== 'file' && this.type !== 'text_area';
},

isTextArea: function() {
return this.type === 'text_area';
},

isCheckbox: function() {
return this.type === 'checkbox';
},

isFileField: function() {
return this.type === 'file';
}
});

Why do you think the input boxes are not appearing on page load?

thanks!

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