Attempted to handle event `becameInvalid` while in state 'root.loaded.saved' - javascript

I've implemented DS.Errors for my RestAdapter, thanks to Alex Spellers tutorial on server side validation.
However, in this part of my app I want to do a simple client side check to see if the form is complete. (Why not have DS.Errors handle all the errors?)
process: function(upload) {
var form = upload.get('form');
if (!isComplete(form)) {
upload.get('errors').add('field', 'field isempty');
return;
}
// else "Processing..."
The logic here is somewhat simplified, but errors.add() should invalidate, and add an error to the model. However I'm getting the following error:
Uncaught Error: Attempted to handle event `becameInvalid` on <#model:upload:54a1f298ef912a2ace760b0f> while in state root.loaded.saved.
I have read about the state manager, but am unsure as to how, and what state I should transition to before adding an error to my model.
Thanks in advance!
Ember : 1.8.1
Ember Data : 1.0.0-beta.11
Handlebars : 1.3.0
jQuery : 1.11.2

After revisiting this I came across the following post. What solved my problem was not sending willCommit, but sending upload.send('becomeDirty'); before executing the following:
upload.get('errors').add('field', 'field isempty');
Now errors can be added as the upload model is not in the saved state.

Related

Uncaught (in promise) Error: Provided weight data has no target variable: block1_conv1_2/kernel

I am new to machine learning and I was following this blog on how to write a model with mobilenet.
I managed to convert the .h5 file model and tried to implement it
on my web app.
Unfortunately, when I try to load the JSON model I get this error:
Uncaught (in promise) Error: Provided weight data has no target
variable: block1_conv1_2/kernel.
Screenshot of the error on a browser
I converted the .h5 model in the command line like so:
tensorflowjs_converter --input_format keras model.h5 ConvertedModel/
The code to load the model in the browser, I followed this blog
let model;
async function loadModel(name) {
$(".progress-bar").show();
model = undefined;
model = await tf.loadModel(`ConvertedModel/model.json`);
$(".progress-bar").hide();
}
To see the code of the model please refer to the blog link.
But below is a screenshot of how the model is compiled.
Model compilation
Dependencies:
Tensorflow 1.13.1
Python 3.6.0
tensorflowjs 1.0.1
Any help to fix this would be appreciated. Thank you so much.
It seems you've encountered this error where an extra suffix has been added to some of your weights.
You can work around this issue by manually removing these extra suffixes from your model.json:
block1_conv1_2/kernel
should instead be:
block1_conv1/kernel
The 'Error in clip' bug has now been fixed so I'm not too sure why you've received this one, but once again you can work around this by manually editing the model.json, and changing every instance of:
{"type":"ndarray", "value":6}
to
6

I am unable to set back data to ckeditor instance which I fetched from it and stored in database?

I have a Django web app which has various instances of ck-editor instances on a web page.By using on blur event I am saving whole of data of the instance in the database -
{% for editor in editors %}
CKEDITOR.appendTo("{{editor.ck_id}}" ,
{
on: {
blur: function(event){
var data = event.editor.getData();
console.log("data of {{editor.ck_id}} is " + data);
var request = $.ajax({
url: "/editor/save/",
type: "GET",
data: {
content : data,
content_id : "{{editor.ck_id}}"
},
dataType: "html"
});
}
}
}
// "{{editor.data}}"
);
CKEDITOR.instances['{{editor.ck_id}}'].insertHtml("{{editor.data}}");
Here ck_id and data are the two database fields of ckeditors.Now suppose I write this on one instance of ckeditor -
Tony Stark
When I lose focus on that instance then on blur event is fired and I use 'getData()' to get the html data of that instance.
<p>Tony Stark</p>
is saved into the database.On the python interpreter now when I fetch editor's data it shows -
<p>Tony Stark</p>
which is obvious.
Now When I re start the server and set the data of every ck-editor instance again then this exception is raised -
Uncaught SyntaxError: Unexpected token ILLEGAL
I know why this is happening - due to this -
CKEDITOR.instances['ck_1'].insertHtml("<p>Tony Stark</p>
");
The data which I sent by fetching from database was -
<p>Tony Stark</p>
and it somehow got converted to above mentioned text with illegal tokens.I have tried to use setData() but with no result. Do I need to encode/decode this HTML or something?
Now my question is how to again reset data to a ck-editor instance which I fetched from it and stored in database. I have posted this question on several forums but many people have got no clue of what I am asking?
Is there anyone here who has tried to do same thing and have succeeded in it?
Thanks
PS: Adrian Ghiuta solution seems to be working but there is just problem. When the editor is loaded first time then in google chrome's debugger inserted line is seen as -
"<p>Tony Stark</p>"
which is rendered due to line "{{editor.data|safe}}".But when I change my editor's content to just
Tony
then in database
<p>Tony</p>
is being saved but when I restart the server it does not render and throws this error
Unexpected ILLEGAL TOKEN
due to this -
"<p>Tony</p>
"
Here ending double quotes are in the next line.But during initial data loading it was on the same line.Might this be causing be any problem?
Because my chrome console shows error at that position.
I will add some images to show the condition.
Initial loading -
Initial console -
Editor after editing -
Error being shown after restarting server and reloading editors -
Console -
You can see how error is thrown at line where double quotes are at the next line.Do I to escape html or something?
Sorry for my naivety but I do not have much command over HTML.

Render React JS server side using .net

I did the comments tutorial on http://reactjs.net/getting-started/tutorial.html and got it to render server side using .net mvc.
I have an existing mvc app where I rewrote a page in react. I'm trying to render it server side using .net but I get an error when it tries to render server side.
Exception Details: React.Exceptions.ReactServerRenderingException: Error while rendering "TopicAnswers" to "react1": TypeError: undefined is not a function
at React.createClass.render (Script Document [8]:80:39) -> var answerNodes = this.props.data.map(function(answer){
at ReactCompositeComponentMixin._renderValidatedComponentWithoutOwnerOrContext (Script Document [2]:7395:34)
Here's the code:
In my MVC view:
#Html.React("TopicAnswers", new
{
initialAnswers = Model,
url = Url.Action("TopicAnswers", new { id = ViewBag.TopicID }),
})
My TopicAnswers.jsx file:
var TopicAnswers = React.createClass({
getInitialState: function(){
alert('inside getInitialState: ' + this.props.initialAnswers);
return {answers: this.props.initialAnswers};
}
My ReactConfig.cs file:
ReactSiteConfiguration.Configuration
.AddScript("~/Scripts/internal/eusVote/TopicAnswers.jsx");
QUESTION: Why is it having a problem rendering the react file server side?
I got this error message trying to render React jsx file server side using .net:
"React.Exceptions.ReactServerRenderingException: Error while rendering "TopicAnswers" to "react1": TypeError: undefined is not a function"
My problem was that in the JSX file, I still had ComponentWillMount which called the loadAnswersFromServer. This is what you need if you are rendering client side. But once you adjust your code to render server side, you need to comment out/remove the ComponentWillMount so that it doesn't try to run the loadAnswersFromServer function on the server side.
With MVC, the data should be passed from the controller to the view and referenced in the #Html.Render("Comment", new { initialData = Model }) for the initial load.
Also, don't forget to comment out/remove the React.render( ... ) line from the JSX file.
alert is available only in browser window context. When rendering it on a server you can not call any functions that are browser related. If you are calling them, then you need to shim them so they are not failing on a server.

little error for a newbie in Javascript MVC

Hi I am just starting a tutorial in javascriptMVC (JqueryMX) I have an error "Uncaught type error Cannot call method 'Model' of undefined" I have checked all path and don't understand why it is still not working. Any help will be greatfull. todo.js below
steal('jquerypp/class',
'jquerypp/controller',
'jquerypp/model',
'jquerypp/view/ejs',
'jquerypp/dom/fixture',
function($){
$.Model('Todo',
{
findAll : "GET /todos",
findOne : "GET /todos/{id}",
create : "POST /todos",
update : "PUT /todos/{id}",
destroy : "DELETE /todos/{id}"
},{})
});
did you have this solved already?
if not, i would suggest that you try the JMVC code generator (./js jmvc/generate/app myapp) as seen in here --> http://javascriptmvc.com/, there you will see how the libraries are placed.
and by the way, the steal.js should be placed in the html file, all others can be in the main js file.

Ember-data resolves wrong API endpoint

I'm having an issue getting Ember.js with Ember Data to hit a nested resource API endpoint. Here is my code:
https://gist.github.com/feliksg/7470254
Here is what i'm using:
DEBUG: ------------------------------- ember.js:3224
DEBUG: Ember : 1.2.0-beta.3 ember.js:3224
DEBUG: Ember Data : 1.0.0-beta.2 ember.js:3224
DEBUG: Handlebars : 1.0.0 ember.js:3224
DEBUG: jQuery : 2.0.3 ember.js:3224
DEBUG: -------------------------------
I'm also using Ember Appkit as the base for this project.
Basically the issue is when I try to submit a new post, ember data does the following:
POST request to /user/posts
instead of a
POST request to /users/1/posts
In addition, for some reason the request payload as shown by chrome inspector shows the form data being passed to the API looks like this:
{ "user/post": { "published":false, "created_at":null, "user":"1" } }
However, I would expect the data to be passed in like this:
{"post": { "body":"some text...", "published":false, "created_at":null, "user_id":"1" } }
So for some reason, it doesn't even pass in the 'body' field even though I have it in the form.
Any help is greatly appreciated!
UPDATE 1
When I visit http://localhost:8000/#/users/1/posts, it sends a GET API request to /users.json. There must be something wrong with the way I set up the PostsRoute but i'm not sure how to fix it.
UPDATE 2
I've updated my PostsRoute to fetch the JSON without using Ember Data which returns the records, but now the posts template does not render. My PostsRoute now looks like this:
PostsRoute = Ember.Route.extend
model: (params) ->
user = #modelFor('user')
userId = user.get('id')
return $.getJSON('http://localhost:5000/api/v1/users/' + userId + '/posts.json')
I also get the following error:
Error while loading route: TypeError: Object # has no method 'slice'
So when you create/use 'users/post' you are defining a namespace where the post lives, not that it's underneath a specific model. AKA, it isn't going to use the associated user model to build up your url, it's just going to make requests using users as part of the post.
I'm not totally positive why the body isn't being attached to the post, are you sure the model includes the body? Are you sure the body property exists on the model you are sending into the createRecord?
BTW, needs doesn't do anything on a route, it only applies to controllers.

Categories