I have below mentioned code in my JS file.
initialize: function () {
if (!$("#Res").is(':checked'))
{
$("#Res").attr('checked', true);
}
}
When I tried to run test case using Qunit.js and blanekt.js. It shows me error that "Cannot read property 'checked' of null"
Can please anyone assist me to fix this issue or re-write test case. I am using Jquery 1.4.1.js version. Is issue related to version of Jquery?
test("initialize test", 1, function () {
$('<input>').appendTo("body");
$('<select>').appendTo("body");
$('<input>', { type: "checkbox", checked: true, id: "Res"}).appendTo("body");
var result = mydomain.initialize();
equal(undefined, result, "passed");
$('input, select').trigger("blur");
ok(true, "blur event called");
$('input, select').trigger("change");
ok(true, "change event called");
$("input").remove();
$("select").remove();
});
Option 1.
Using your browser's dev tools, execute the following command:
$("#Res")
If you come up with null it means that your control isn't being created as you were expected.
Option 2.
If Option 1 is fine then you might be calling the initialize function before the input is created.
In any case it is difficult to help you because you haven't posted the resulting HTML by viewing the source of the page once it loads.
Option 3.
Checkbox libraries commonly use css and hide the actual checkbox input after they've initialised. You should check for available events or properties to check their state.
Related
I currently have this Code SandBox where I am trying to get React-Quill and Quill-Comment to work together so that I can let users comment on content that has been written.
Quill comment is not a react package and I am a react noob so I don't know if what I am trying to do it even possible. It appears to partially work because the toolbar add comment button registers the click event.
let commentCallback;
function commentAddClick(callback) {
setOpen(true); //show the modal
commentCallback = callback; //Appears to do nothing?
console.log("callback :>> ", callback); //Nothing is ever in the callback
console.log("commentAddClick");
}
However, the callback value doesn't appear to have or do anything. When I click the add comment button in the modal:
const commentSave = () => {
const comment = "This is a comment, forced for testing";
commentCallback(comment);
console.log("comment :>> ", comment);
//let comment = $('#commentInput').val();
commentCallback(comment);
addCommentToList(comment, currentTimestamp);
};
it throws an error that tells me
commentCallback is not a function
I am attempting to following the Vanilla JS example see line 68 here. I assume this problem is related to this warning message that spams on every keypress.
quill:toolbar ignoring attaching to nonexistent format comments-add
<button type="button" class="ql-comments-add"></button>
How do I resolve the warning message, and get the callback to work? Or, secondarily, is there another good commenting library that will work with Quill?
A working example in Vanilla JS can be found here:
https://github.com/nhaouari/quill-comment/tree/master/example/quill-comment-test
I'd like to replicate this in React.
The library you are referring to says that callback function will be null when nothing is selected in the editor. So, you need to select some text in the editor for the callback function to work.
I need to get a selected value using dojo, from the dropdown without redirecting to another page.
I have tried something like this:
dojo.addOnLoad( function() {
dojo.connect(dojo.byId('#inquiry_type'), "onchange", function(evt) {
alert("changed!");
console.log("option Changed to: "+evt.target.value);
dojo.stopEvent(evt);
});
});
Above code gave me undefined in console. Can anyone help me with dojo code?
Omit the # in your call to dojo.byId. It just needs the name. Using the # syntax is what you would do with dojo/query.
I have a complex function that loops through the elements during the onSuccess: of my js and I'm getting the following error that I haven't seen before.
exception encountered : {"message": "Invalid argument.", "description": "Invalid argument.", "number": -2147024809, "name": "Error"}
The js function looks like this:
if(Object.isArray(list)){
list.each(function(listItem, index){
if(!Object.isUndefined(listItem.disabled)){
listItem.disabled = disableFlag;
}
});
}
that is called from the onSuccess: portion of an Update. My html is a button that is calling the noted function from an onclick. When I run it the onException: always happens and I'm getting the error by:
Object.toJSON(exception)
Has anyone seen this before? I have tried playing around with the functionality and it seems that when I use the button to do what it's supposed to do after a specific sequence of events is the only time this happens. So, I placed an arbitrary link on the page and wanted to see if I clicked that, what would happen and it updated the JSON object on the page and allowed for me to use the button for it's set action without the error. Any help would be appreciated.
Most of the time this kind of error happens in IE when you set an attribute of a DOM element.
If listItem is DOM element then maybe it's not yet added to the document or disableFlag is an invalid value. Or the error happens outside the provided code.
I'm using a jQuery plugin called toggleEdit for inline editing.
Everything works fine when the code is actually used in the page.
However, my test suite fails with the following error:
TypeError: Cannot call method 'remove' of undefined
I tracked it down to be triggered from within the clear method of this particular plugin. Its source file can be found here.
There are two relevant bits in that code:
1- The _init function
self.element.addClass("toggleEdit toggleEdit-edit toggleEdit-edit-" +
self._tag(self.element))
//store reference to preview element
.data("toggleEdit-preview", self.p);
As you can see, when the plugin is first instantiated it uses the data structure on self to store the newly created element.
2- The clear function
self.element.data("toggleEdit-preview").remove();
The clear function then tries to access that structure and retrieve the element. That's when, while inside a jasmine spec, it fails with the aforementioned exception.
Has anyone seen anything similar?
EDIT:
This is my spec, it's the simplest piece of code able to reproduce the error:
it("should update the given attribute on the server", function(){
$('#user-details input, #user-details select').toggleEdit(); //this line triggers the error
});
http://alz.so/static/plugins/toggleedit/jquery.toggleedit.js
I was taking a look at the source for toggleEdit and it seems that the only 2 times the function clear is called is just before self.element.data gets set:
if (typeof self.element.data("toggleEdit-preview") !== "undefined") {
self.clear();
self.disableEvents();
}
And at destroy function:
destroy: function() {
var self = this;
self.clear();
self.disableEvents();
$.Widget.prototype.destroy.apply(self, arguments);
}
Since the first call seems to be protected, I ask you a somewhat dumb question: Is it possible that destroy is being called twice?
Found my problem: old version of the jQuery + jQuery UI duo. Upgrading them resolves the exception.
I'm having what I hope is a simple-to-fix issue.
Basically, I've got one block of javascript containing the function, and then I'm trying to call it from another block of javascript (within a jQuery $(document).ready function). Whilst it works fine on Firefox, I get an 'Object Expected' error in IE7. It's probably something to do with scope, but I'm not sure what to fix. Firebug doesn't seem to give any light on the subject.
So, here's my function:
<script type="text/javascript">
//<![CDATA[
function onsite_validate(){
$("#tsp_onsite_form").validate({
errorClass: "form_error",
errorElement: "em",
errorPlacement: function(error, element) {
error.prependTo( element.parent("label") );
},
highlight: function(element, errorClass) {
$(element).addClass(errorClass);
},
unhighlight: function(element, errorClass) {
$(element).removeClass(errorClass);
},
rules: {
fault_found: "required"
},
messages: {
fault_found: "was a fault found?"
},
submitHandler: function(form) {
$.blockUI();
form.submit();
} //ends submit handler
});
}
//]]>
</script>
and after this, I have the following:
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
onsite_validate();
});
//]]>
</script>
The 'Object Expected' error throws on calling onsite_validate();
I'm sure I'm making a fundamental mistake - just can't seem to spot it!
Many thanks
What type of object is error in errorPlacement? Not entirely sure if it's passed as an instance of jQuery, but if not, you might need to work around that.
Edit: just realized you said it works in non-IE. I remember having this error in IE7 only, and having to patch the jQuery source to handle it. What version of jQuery are you using, and are you hosting it yourself or using something like GoogleAPIs? Also, can you provide the exact error (file, line, etc)?
I've had this error when trying to load the same javascript file twice (in nested templates). It was difficult to identify because the problem occurred elsewhere in the flow.
What I'm saying is that the error isn't necessarily with that function or even that code block.
Sounds like you have a null reference in one of those callback functions.
Just for debugging, you might try checking each of the objects against null and throwing an alert as needed to figure out which object isn't getting set.
For example, check these objects:
element.parent
error
$(element)
In IIS
Click on your website[LHS]=>Authentication[**Features View on RHS**]=>Enable only Anonymous authentication other should be disabled and click on edit, set Specific user to **IUSR** instead of [IUSR_Servernname] and No password is required