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

Allow custom submitType #72

Open
mstn opened this issue Aug 5, 2015 · 2 comments
Open

Allow custom submitType #72

mstn opened this issue Aug 5, 2015 · 2 comments

Comments

@mstn
Copy link

mstn commented Aug 5, 2015

As far I understood, forms are submitted on 'submit' event or on enter pressed. However, it would be nice also to have these cases:

  • click on an arbitrary jquery selector. For example "click a.btn"
  • change/keyup on inputs. For example, when inline editing properties of a collection item.

I found a hack that looks like this

  Template.MyCustomForm.events({
     'change input': function(event, template){
        template.reactiveForms.submit();
     }
  });

It works, but the package should handle those cases imo. In addition, it would be nice to specify if triggering events are mutually exclusive or inclusive. In other words, a form is submitted on enter and on submit, but not on change input.

@jonjamz
Copy link
Owner

jonjamz commented Aug 5, 2015

I would prefer if form blocks were only concerned with things relating to form blocks. This keeps things reusable.

Your idea of allowing more than one event (or what you could fit inside a single event map) to submit the form is good, but I have yet to personally encounter a situation in which I need such functionality on the actual form block configuration. I would be happy to read more of your thoughts surrounding this, though, because the functionality would be trivial to add.

It's probably not a good idea to manage the element-level events that could submit a form on the form block configuration with a more complex API. It won't scale well as you try to balance conflicting scenarios--adding more granular selectors or using e.stopPropagation() in event handlers to stop the change event from bubbling up in certain cases will quickly become a maintenance headache.

To address your specific example--a better way for you to do it would be like this:

// This would go on the template surrounding the form block instance.
Template.MyCustomFormContainer.events({
  'change input': function(event, template){ 
    template.find('form').submit();
  }
});

Now your code is free from package-related hacks, and that special functionality is limited to just this instance where you need it.

@mstn
Copy link
Author

mstn commented Aug 6, 2015

Thanks for your answer and for the final suggestion. I have encountered two cases where this proposal could be useful.

  1. A form for editing properties of an item in a collection. For example, I want to change some properties in user profile: name, surname, address and so on. However, I want to do it in a "fluid" way as if the properties were independent from each other. It is quite common to have an input form without an explicit "submit" button where values are updated on the fly as soon as they change.
  2. Sometimes people prefer to use an anchor tag as submit button or another html tag. I don't want to say this is the best or cleaner way to do it, but it happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants