ember-form-for | This Ember | Addon library
kandi X-RAY | ember-form-for Summary
kandi X-RAY | ember-form-for Summary
This Ember.js addon will give you an easy way to build good forms:. WARNING: This addon uses contextual helpers and is therefore only compatible with apps built with Ember.js version 2.3 and up.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ember-form-for
ember-form-for Key Features
ember-form-for Examples and Code Snippets
Community Discussions
Trending Discussions on ember-form-for
QUESTION
I have a /posts/new
route for creating a new post
record. I am using the ember-form-for add-on, which provides helpers for creating forms. You are supposed to pass the form-for
component an object, and when you submit the form, form-for
calls the save()
method on the object. So it looks like you're supposed to pass it an instance of a model directly.
This means that I need to create a new post
model instance automatically when I navigate to this route. This is all good so long as I submit the form and create the new model instance. But what if I go to this route and then leave without submitting (i.e. saving) the new instance? It seems this will leave an unsaved model instance lying around in the store. Do I need to manually destroy this instance if I navigate away from the route, or is there some more elegant way to do this? If I do need to manually destroy it, what's the appropriate hook? deactivate
is a route method but my new instance is stored on the controller.
NOTE: I've seen this existing answer, but it's from 2013. Wondering if there's something cleaner available now.
...ANSWER
Answered 2018-Jun-01 at 06:02Since you are creating a new model, you need to manually destroy it (roll it back). This can be done in the route's resetController
hook. Something like below:
QUESTION
I'm trying to understand the issue in the ember-form-for (https://github.com/martndemus/ember-form-for/blob/master/addon/components/form-field.js#L64) but IMHO the code is not that important, it is just an ordinary component.
The component works perfectly when re-rendering does not occur. In the init() we will do set(this, 'name', 'value') and it works as expected. But after re-rendering, the init() is not called as expected (https://guides.emberjs.com/v3.0.0/components/the-component-lifecycle/), the object has same identifier as before rendering but the value that were set in the init() are lost. And I do not understand why.
...ANSWER
Answered 2018-Feb-28 at 10:43In the ember guides we learn that there is a lifecycle hook that will get called on rerender as well, the didReceiveAttrs
hook.
So, use this and your component will change the state accordingly to the changed attributes.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ember-form-for
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page