I'm not sure why im getting the error, but i'm getting "cannot call method replace of undefined". It's happening on the the $('#wizard'+optionalArg) part, if I remove the optionalArg part it works fine. Any idea why this is happening?
function loadWizard(optionalArg)
{
optionalArg = (typeof optionalArg === "undefined") ? "" : optionalArg;
$('#wizard'+optionalArg).smartWizard({contentURL:'/welcome/form_view',
transitionEffect:'slideleft', onLeaveStep:leaveAStepCallback,onFinish:onFinishCallback, contentCache:false});
}
function call
var id = 2;
loadWizard(id);
before I send over the ID i run this
$('#all_wizards').append('<form action="#" method="POST"><div id="wizard2" class="swMain template"></div></form>');
so wizard2 should exist..
It can be:
$('#wizard'+optionalArg) //would make wizard2
there is no element in your html with this id, so calling method on undefine throw exception.
Try with null check:
function loadWizard(optionalArg)
{
var myElement=$('#wizard'+optionalArg);
if(myElement.length>0){
$('#wizard'+optionalArg).smartWizard({contentURL:'/welcome/form_view',transitionEffect:'slideleft', onLeaveStep:leaveAStepCallback,onFinish:onFinishCallback, contentCache:false});
}
}
Are you sure you have an element with
id="wizard1" (assuming optionalArg = 1)
Debug by putting a console.log to ('#wizard'+ optionalArg) and check whether the element exists? most likely the element does not exists and hence creating and error.
Related
I would like to modify the $(document).ajaxStop function to set the localStorage variable when it is called (without actually changing the function that it calls). What I have tried is something like this:
origstop = $(document).ajaxStop;
$(document).ajaxStop = function(fun) {
localStorage.var = 'nice';
origstop(fun);
}
This did not work because it changes back right away, so when I run $(document).ajaxStop I get the same function as origstop.
Another way that I have found on StackOverflow is this:
(function($){
var jqAttr = $.fn.attr;
$.fn.attr = function( elem, name, value, pass ) {
if (name === 'ajaxStop') {
localStorage.var = 'nice';
jqAttr(elem, name, value, pass);
} else {
jqAttr(elem, name, value, pass);
}
};
}(jQuery));
This causes an error Uncaught TypeError: Cannot read properties of undefined (reading 'length') whenever the function is actually called. Also, I am also not sure how this works, so I have no idea how to fix this either...
What would be the correct way to approach this?
First I made function:
function createComment(template) {
let emoji = document.getElementById("emojis").value;
let comment = template.replace(/p/g, emoji)
document.getElementById("comment").innerHTML = "kok" ;
}
and in HTML button : <button type="button" onclick="createComment()">Go</button>
but, I wanted to remove template argument from function because button didn't work so I just reduced JS function to :
function createComment() {
//let emoji = document.getElementById("emojis").value;
//let comment = template.replace(/p/g, emoji)
document.getElementById("comment").innerHTML = "kok" ;
}
but even now developer tools report error Uncaught TypeError: Failed to execute 'createComment' on 'Document': 1 argument required, but only 0 present.
If I change function name to anything to anything else like from createComment to createCommentS and in button too it works. For some reason it just keeps on hanging of original function argument and it's stubborn doesnt wanna give up on asking argument. Why?
Rename the function to something else because it is probably being shadowed by document.createComment()
This is my JavaScript function
function movements(remove) {
var op = remove ? 'remove' : 'add';
crossvent[op](documentElement, 'selectstart', preventGrabbed); // IE8
crossvent[op](documentElement, 'click', preventGrabbed);
} function move(value) {
And this is how it's called
movements();
You can find reference for in jkanban.js file.
Now I have to change it to Typescript and I got this error on function calling,
Expected 1 arguments, but got 0
How can I resolve this problem in typescript ?
Simply add the question mark to the argument that requires your function, example:
function movements(remove?) {
// ...
}
You need to specify the input for calling movements().
You can set default to the variable using this:
function movements(remove = null) {
so that the function won't break even if you don't give it the input.
You can default it to anything you like though.
In 0.7.2, I could have something like this
<span>{{color 'blue'}}</span>
Handlebars.registerHelper('color', function (parameter) {
return Session.equals('color', parameter) ? 'blue' : 'red';
});
and it would work perfectly fine. What is the equivalent in the 0.8.0 release? I know they replaced Handlebars.registerHelper with UI.registerHelper, but this
UI.registerHelper('color', function (parameter) {
return Session.equals('color', parameter) ? 'blue' : 'red';
});
still returns this error
Exception in Meteor UI: Error: Can't call non-function: [object Object]
Any help?
Turns out it was all because one of my registerHelpers was the word 'parent'. Using that threw an error so it made it seem like all of my helpers were messed up. I'm guessing that it's a reserved word.
I'm doing this & it works (exactly as I use it). Do you use iron-router? This might do too.
UI.registerHelper('routeActive', function(routeName) {
var route = Router.current();
if(route && route.route && route.route.name == routeName) return 'active';
});
Then you can use the name of your template/route in routeName
I'm a bit unsure why you're getting that error are you sure its from the Handlebars expression.
You probably need to pass the parameter with a name:
<span>{{activePath path='home'}}</span>
UI.registerHelper('activePath', function() {
return Session.equals('activePath', this.path) ? 'active' : '';
});
Take a look at this:
if(session.getAttribute("mode")!=null){
mode = (String)session.getAttribute("mode");
}
The first time value for the mode is empty so I set the mode value to a script variable like this:
var mode='<%=mode%>';
below is the method in which I call on load of the form, but it says mode is undefined
bodyOnLoad();
var mode='<%=mode%>';
alert("mode : "+mode);
function bodyOnLoad() {
if(mode.length < 0){
alert("mode empty 111111");
document.getElementById("functiontype").value="view";
document.getElementById("page").value="1";
document.forms["frmTempcard"].submit();
return;
}
}
Can anyone help me with this?
Declare the variable first. The mode is undefined when you call the function bodyOnLoad.
var mode='<%=mode%>';
bodyOnLoad();