I am trying to build out edit functionality for a Goal record. On the Goal index page, there is an edit button next to each goal. When clicked, each field becomes editable. Upon clicking Save, the changes are saved to the server. So far so good.
There is also a Cancel button. When a user clicks it, I need to reset the state of the model to what it was before they changed things. goal.rollback() in the controller works fine for this. Except, if the user has already clicked Save but there were server side validation failures. In this case, attempting to rollback() throws Uncaught Error: Attempted to handle event `reloadRecord` on <App.Goal:ember123:1234> while in state root.loaded.updated.invalid.
If instead I try to goal.reloadRecord I get Uncaught Error: Attempted to handle event `reloadRecord` on <App.Goal:ember123:1234> while in state root.loaded.updated.invalid.
Same deal with goal.unloadRecord. I have tried massaging the state like this:
state = goal.get('currentState') #this code makes me sad.
state.isValid = true
state.isError = false
And like this:
goal.transitionTo('loaded.saved')
To no avail. Is make zero sense to me the reloading or unloading a record should be statefull.
Any assistance would be greatly appreciated. Again, I'm trying to take a dirty, invalid record in ember and get it back to a happy state either by rolling back changes, or just reloading it from the server.
EDIT: Ember-data v1.0.0-beta.3-4-g169793e, ember Version: 1.1.2
Here's a working example, change the color then hit save.
http://emberjs.jsbin.com/OxIDiVU/44/edit
PR submitted https://github.com/emberjs/data/pull/1590
Related
On my page a I have a PL/SQL process that updates the database. If the process is successful, I want to display a success message. The way I am doing this now is by setting a Success Message property of my process to a page item that contains success message - &P1_SUCCESS_MSG.
I also set Error property of my process to &P1_ERROR_MSG..
Both P1_SUCCESS_MSG and P1_ERROR_MSG gets set inside the process. Now the issue I have is when the user clicks the Save button, thus activating the process, without changing anything one the form. The success message is displayed regardless if any changes were made. I was wondering if there is an easy way to check if the form was changed and prevent the success message from being displayed if not changes were made to the database
If success message is displayed, it means that :P1_SUCCESS_MSG has value. Why? It should be empty by default and set only if procedure completes successfully and changes something.
For that purpose, I'd create a stored procedure with one (or two) OUT parameter(s); the same parameter might be used to inform user of what happened. That OUT parameter would be used to set :P1_SUCCESS_MSG item's value.
So, if something has been done, it would say e.g.
Procedure successfully completed.
Otherwise,
Nothing has been done.
In ember, I have a form which ask the user their username and password for our remote server and then I want to verify the credentials by making an ajax call. Currently, I am using a custom made component which allows me to bind any action on clicking next or submit where I can verify the credentials and throw errors if needed. But once an error will occur, user cant click the next button (the way component is implemented) and hence second time validation is not happening. So, I thought to make a computed property which will look for username and password (and hence make ajax call when entered). But the problem with this approach is: every time something is entered in these boxes, computed property gets triggered which makes an ajax call (i dont want to make so many network calls for no purpose). Is there a way in ember where we can wait for user to finish the input and then invoke any kind of action?
Better approach is to use oninput with action:
<input oninput={{action "onInput" value="target.value"}}>
and then from action onInput debounce call to ajax function using debounceTask from ember-lifeline addon(this example), or using ember-concurrency:
actions: {
onInput(val){
debounceTask(this, 'sendAjax', val, 500);
}
}
All,
I have searched around for an answer to this but have yet to find a good explanation and solution. Hopefully, you can help.
I have a route that renders an Ember.ContainerView (as opposed to a standard Ember.View). When I transition away from this route and then back to it (either via the back button, a link-helper or just changing the url) I get the following error in the console:
Uncaught Error: Assertion Failed: calling set on destroyed object
I understand that a high level reason for this is that when we transition away from the route with the ContainerView, it's childViews are marked as destroyed. When we transition back to the route, the problem has something to do with Ember trying to set the childViews back to the destroyed instances.
I'm not exactly clear but that is the vague understanding I currently have.
So, my questions are as follows:
Can you please correct my understanding of this problem if it is not correct?
Can you please tell me how to fix this error?
For your convenience, I have created a JSBin example for your viewing pleasure. To replicate the error, open your JS console, click on the Go to Route two link, then click on the Go to index link. Now check your logs.
Thanks in advance for any assistance you can provide.
Here is the fix: http://jsbin.com/jumoy/1/edit?html,css,js,output
I have encountered this problem before. I can't say I truly understand it at a very detailed level, but here is the general problem. When you are defining your container view, it is actually creating that subview when you define it, not when you create an instance of the view. This means that your childview 'initial' is only being created one time, and thats when the file is initialled parsed and the ContainerView is defined. When ember cleans this childview up, it is not gone for ever and 'initial' will always be equal to a cleaned up view.
By setting 'initial' as a property, it will be created every time a new instance of your container view is rendered, and therefore a new childview will be created and accessible.
So moral of the story, try not to create objects in definitions of controllers/views. Instead create properties that return the creation of that object.
Hope this helps and makes sense.
UPDATE::
I have edited the jsbin to show you on a deeper level what is happening and why it isn't working. To see the effect uncomment the second ContainerView and comment out the first, you will notice in the console logs that the second time you go to the twoRoute, it has marked that initial property as state: destroying for the view.
http://jsbin.com/jumoy/2/edit?html,js,output
if you are using Ember.Instrumentation namespace for publishing your events and Ember.subscribe to listen to them in your code, when you publish events, it stack all the subscribers and call them even when they are destroyed.
so basically, when for example your route is destroyed which is running subscribe statements it will fail and give above error.
Here is a solution to this problem: Use Ember.Instrumentation.reset() to remove previous subscribers which are destroyed. This solution helped me in acceptance tests where app was destroyed after tests are finished.
I wrote Ember.Instrumentation.reset() in startApp function of module-for-acceptance.js and it worked.
Hope that helps.
I use Ember data with the REST Adapter. I want to make sure that in case of slow server responses, the application does not fail.
I have simulated this bij adding at server side a sleep method of 5 seconds before returning the JSON response.
If you have a form with a SAVE button, and you click this button while a previous save is still is progress, you receive a inFlight error and the whole Ember app freezes (only thing you can do is reload app). So, you can easily disable the save button by checking the isSaving state:
<button {{action 'save'}} {{bindAttr disabled="isSaving"}}>Save</button>
Now it also seems that when changing a form field while a previous save is still is progress, you receive a inFlight error. This would thus indicate that I also need to disable the complete form.
Uncaught Error: Attempted to handle event `willSetProperty` on
<App.Author:ember477:5203e34599808d1c6c000001> while in state
rootState.loaded.updated.inFlight. Called with {reference: [object Object], store:
<App.Store:ember541>, name: name}
Is there a known good practice to handle these cases ... I want to prevent that I need to add a lot of logic (disable buttons, set fields readonly, etc.) for these edge cases.
It may not be within the scope of what you are trying to do, but the Ember Persistence Foundation is designed to allow updating your models while a save is still in flight.
It is relatively trivial to migrate your models to EPF, but there are some changes required in the controller code, see "Migrating from Ember Data".
We are using Eclipse API in our RAP application.This uses Eclipse Modeling Frame Work.
When a page gets edited, Model Becomes Dirty and as a Result,Save Button gets Enabled.
In our editor pages, when ever there is an error in the Page, we set the Validation flag of the Editor page to false, which would in turn display red colored marks on the page.Then usually save button is also becoming enabled.
But, I want to change this behavior.When some error mark appears on the page, I don't want to get the save button enabled,.It shouldn't allow the user to save the model in the error stage.
The save button should be disabled, How can I achieve this.
Kindly clear my doubt.
The editor generated by EMF uses a commandstacklistener to fire a PROP_DIRTY to the editor. If this property is fired, the underlying framework will ask the editors #isDirty Method for the dirty state. This is the place where you can implement your logic.
#Override
public boolean isDirty() {
Diagnostic diagnostic = validateMyModel();
return ((BasicCommandStack)editingDomain.getCommandStack()).isSaveNeeded() && diagnostic.getSeverity() == Diagnostic.OK;
}
This case doesn't cover the usecase, that the editor could have been already dirty when the user makes a not-valid edit on the model.
But that is not the best way IMHO. Because if the user closes the editor all changes of the model are lost, without any notification (because of the missing dirty-flag). So he probably did 100 valid modifications, 1 invalid and loses his changed model.
A better way is to show a warning-message if the user wants to save the dialog. If there are errors in the dialog the editor cannot change its state from dirty to not-dirty and the user has to
correct all erros or
close the editor and looses all his changens
To achieve that you have to implement in your doSave(IProgressMonitor progressMonitor) method a dialog to show the errors. The more tricky part is to override the default-behavior of closing a dirty editor. The workbench will show a dialog with, Yes, No and Cancel
To override this behavior you have to implement the interface org.eclipse.ui.ISaveablePart2 in your editor to override the promptToSaveOnClose() method. In this method there must be again your logic that checks for errors in the model. If there are errors, this method has to return ISaveablePart2.CANCEL so that editor is not closable as long as there are errors in the dirty model.
HTH Tom