working with CKEDITOR and trying to disable the submit button if the length of the content is 0, but then on keyup, check the function again and see if the value is more than 1 and if so set the submit button to enabled.
So here we have this:
CKEDITOR.on('instanceReady', function(){
disableNewPost();
var e = CKEDITOR.instances['newpost'];
e.on( 'keyup', function() {
disableNewPost();
});
});
function disableNewPost() {
var value = CKEDITOR.instances['newpost'].getData();
var valueL = value.length
if ($(valueL) < 1) {
$(".addnewpostbtn").prop("disabled", true);
} else if ($(valueL) > 0) {
$(".addnewpostbtn").prop("disabled", false);
}
}
This gets the value and length correctly, and if put an alert(value) or alert(valueL) it displays what it shoudld.
However the if statement doesnt seem to work.
Onpage load, the CKEDITOR has no content, and an alert shows its length as 0.
However using the above if statement it doesnt disable the button. I have tried all variations i can think of ( == '' / == 0 ) etc. But no luck.
If the function just contains:
$(".addnewpostbtn").prop("disabled", true);
Then it does disable.
Any help?
$(".addnewpostbtn").prop("disabled", $(valueL) < 1)? (But the real problem is that$(valueL)will always be truthy.)$(".addnewpostbtn").prop("disabled", valueL > 0 && value L < 1);value.lengthis a Number, why on earth would you want to wrap it in jQuery$(valueL)?