how come that when I attach onchange by attribute and call it
onchange="validateDate(FPR_CURR_FROM);"
it works, but when I use a ASP .NET validator, and my attached function is called like :
function anonymous() {
ValidatorOnChange(event);
validateDate(FPR_CURR_FROM);
}
I get error: FPR_CURR_FROM is undefined.
First off: I know that using FPR_CURR_FROM to access element is BAD, and I should use getElementByID etc... And I will change it eventually. But as I bumped into that code, I'm curious what caused it - propably visibility of variables I guess.
I think it's a scoping issue, yes, it would take seeing more code and how anonymous is called, but that is what it looks like to me from what I see... One way around that is to attach the FPR_CURR_FROM variable to the window object, and access it via window.FPR_CURR_FROM...
Related
I'm just starting out with RactiveJs and having a few troubles with observing an input tag, which is initially rendered with a value.
I'm observing a the input field below.
{{#invoices:i}}
<input class="text-center" type="date"" value="{{***date_modified***}}">
{{/invoices}}
Using the below
ractive.observe({
'*.*.date_modified': function(newValue, ***oldValue***, keyPath) {
// some function
};
});
The challenge is the first time "date_modified" is the changed "oldValue" is undefined. The second time "date_modified" is changed "oldValue" correctly returns the old value.
The "date_modified" is initially rendered with a value (e.g., 22/11/2014), which I suspect might be the issue as all of the examples leave the input blank when the template I
Any thoughts?
Thanks
By default, observers 'initialise' with an undefined oldValue - the idea is that it's often easier to write a single function that does something with the current state of the app, regardless of how that state came to be, rather than some initial setup logic plus a separate change handler of some kind.
But you can disable that first call by passing an init: false option, like so:
ractive.observe('foo', handler, { init: false });
However there's a bit more to it than that in this case. It turns out you've uncovered a bug - pattern observers can't have a * as the first key. You'd need to use invoices.*.date_modified instead of *.*.date_modified. An issue has been raised on GitHub - thanks!
I have an observer to a value "App.selectedValue". I also have another Ember object that has a binding (App.someObj.appValueBinding) to App.selectedValue. However, when my observer is called, the binding of App.someObj is not updated.
This is illustrated in http://jsfiddle.net/Ur2Qj/8/
In the jsfiddle, you can see in the Chrome debugger or FireBug, that App.selectedValue and App.someObj.appValue have different values, even tho' the latter is bound to the former.
Seems like the binding should be updated when the observer is called. Is this expected behavior in Emberjs or is it a bug? Is there a work-around?
Thanks for looking at this!
Take a look at this: http://jsfiddle.net/ud3323/GUHCD/ (in JavaScript; I don't like CoffeeScript... sorry).
The two main things you've got wrong here is not using get() and set() properly and in your observer you need to set App.someController.content after the end of the current runloop (which means after all the other bindings have taken place). You do this by using Ember.run.next(). You could also use Ember.run.sync() there as well.
Oh and you need to use jQuery 1.7.1. Version 1.5.2 is not compatible with Ember.
I tried to change like that(worked on the 'navigator' object)
page->mainFrame()->evaluateJavaScript(
"var navigator=new Object;"
"navigator.someProperty=...");
In that case, I would use the signal javaScriptWindowObjectCleared
That kicks in just before load, when the window has been cleared.
You probably want to validate the origin before doing anything, though.
That being said - and I am not too sure what you want to achieve - I wouldn't manipulate the javascript scope like that. Maintaining and deploying javascript is easier than doing the same for C++. So, I would instead just expose a simple C++ object to the javascript scope (via addToJavaScriptWindowObject), and then have the javascript code test this object and do what it has to do.
Either way, hope this helps.
I have a repeater that populates a component, called 'project'. The project components are given an ID of 'wholeProject'. In all of my functions up until now, I was able to determine how many project components were made by doing the following:
wholeProject.length;
I used this in for loops, for each loops, and for changing the item settings within a project, i.e. something like this:
wholeProject[i].studentName = "Billy Bob";
However, I'm creating a new function that does not seem to like this wholeProject.length reference. I'm using it within the same level as all the others (i.e. the parent level). So far, my function is simply this:
public function getStudentYears():void
{
Alert.show(String(wholeProject.length));
}
when the application loads, the alert message simply does not appear. If I change the alert to something like this:
Alert.show("This is just a test.");
it works just fine. But for some reason, the wholeProject.length doesn't work in this function whereas it does in all my other ones. Anybody have any ideas as to why this is happening?
Use your repeater's data provider length instead.
I am working with a pretty complicated .aspx page that is full of controls (Telerik, Ajax, etc.) that all expand, collapse, show, hide, etc. when the page is loaded. Since this rendering happens on the client-side and can take different lengths of time based on the users machine specs, is there a way to detect when all (or some) rendering has taken place (jQuery?) so I can then act on specific elements, knowing they are fully rendered?
JavaScript is single threaded. The time passed to setTimeout is a minimum, but not a maximum, so if you pass something like 10(ms), you essentially are saying "execute this code after all the currently running code is finished."
So, if all the controls use $(document).ready() to do their thing, all you need is:
$(document).ready(function() {
setTimeout(function() {
doStuff();
},10);
});
doStuff will be called after all the functions passed to $(document).ready have run. However, this isn't foolproof. If the controls have their own way of detecting whether the document has loaded, or do their own setTimeout(), you're in trouble. The problem is that JavaScript does not guarantee the execution order of setTimeouts. Sometimes your code may run last, other times it may run before the setTimeouts used for the animation.
One last idea: if all the animation is done using jQuery, then the effects run in a single queue. In doStuff you could add an animation of some sort with a callback and be reasonably certain that the callback would run last.
Whenever I had to wait for multiple things to be ready before proceeding, I would create an array with true/false values. Every mandatory part of the page got an event which, when it is called, updates the specific entry in the array to true. Also, it called a general function which returned true if all values in an array was true, otherwise false.
If that function finally returned true, I would proceed with the execution. It is especially useful if you have to wait for an AJAX call to end but don't want to use async = true. It also is useful if you want to start loading multiple things at once instead of one after another, since they all report ready-state to the same array.
It does however use global variables so you might need to do some optimizations. You might not want to do this approach either if you have a grudge against global variables.
You should place your code inside the jQuery $(document).ready() function. This will ensure that all elements are loaded before the code runs.
http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
I think the doc you need is:
http://docs.jquery.com/Events/load
"I can then act on specific elements, knowing they are fully rendered?"
You can use the load method (linked above) to attach to any element. So if you had a div with an id of "lastElement", you could write
$('div#lastElement).load(runThisFunction);