Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

job-submission.js throws js error expects job_description to be WP Editor #1808

Closed
tripflex opened this issue Jun 25, 2019 · 5 comments

Comments

@tripflex
Copy link
Collaborator

commented Jun 25, 2019

setTimeout( function() {
if ( typeof tinymce === undefined || tinymce.get( 'job_description' ) == null ) {
return;
}
tinymce.get( 'job_description' ).on( 'Change', function () {
var editorTextArea = $( '#job_description' );
editorTextArea.hide();
editorTextArea[0].setCustomValidity( '' );
editorTextArea[0].reportValidity();
});
}, 1000); // 1 second delay to wait for tinymce to load

If a user modifies (via plugin or PHP) the job description field to change it to say, a textarea, this will result in JS error on the page, as TinyMCE might not even be set.

Probably should add a conditional if statement around it to check if tinymce even exists on window object before assuming it does

@tripflex

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 25, 2019

So this is an issue but not because it's not being checked, but because undefined is being checked incorrectly.

@tripflex tripflex closed this Jun 25, 2019

@jom

This comment has been minimized.

Copy link
Member

commented Jun 25, 2019

Actually, I’m wondering if this should be && instead of ||.

return typeof tinymce !== undefined ||

The check in the setTimeout() looks good, though.

@tripflex

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 25, 2019

@jom yeah i agree it should be && because tinymce should exist AND job_description not equal to null

@tripflex

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 5, 2019

So i'm going to re-open this issue, as this is still a problem, but it's due to checking against undefined without quotes, when it should be in quotes

@tripflex tripflex reopened this Jul 5, 2019

@tripflex

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 5, 2019

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined#Typeof_operator_and_undefined

Example:
https://glot.io/snippets/fdt65d486p

In the case where job_description is not using WP Editor (or any other field on the page), tinymce is never actually loaded on the page, so it must be checked against "undefined"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.