Multiple "data('object').editor" editors

I have used custom error messages with page titles in the past with the following syntax:

var pageTitle = $(‘#MyPageTitle’);       
var editor = pageTitle.data(‘object’).editor;
editor.handleMessages([{message:‘Account billing address is incomplete’, severity:‘ERROR’}]);

I recently tried using 2 different page titles with 2 different Ids to have 2 different error message locations like so:

var pageTitle = $(‘#MyPageTitle’);       
var editor = pageTitle.data(‘object’).editor;
editor.handleMessages([{message:‘Account billing address is incomplete’, severity:‘ERROR’}]);
var errorPageTitle = $(‘#MyErrorPageTitle’);
var errorEditor = errorPageTitle.data(‘object’).editor;
errorEditor.handleMessages([{message:‘Account billing address is incomplete’, severity:‘ERROR’}]);

It seemed to work for a bit, but recently I’ve been getting errors on this line:

var errorEditor = errorPageTitle.data(‘object’).editor;

that editor can’t be read/ it’s undefined. Can this not be used 2 times on one page?

        

If it’s breaking on that line, that means that errorPageTitle.data(‘object’) is what’s undefined, not .editor, so I would check to make sure that the errorPageTitle is in fact present, e.g. do this:

var errorPageTitle = $(‘#MyErrorPageTitle’);
console.log(errorPageTitle);

and see if anything comes up for errorPageTitle, or if it’s undefined / an empty list. If so, then check the Unique Id on your Page Title to make sure it’s correct.

Thanks Zach it was a problem with the Unique Id, sometimes you forget about the little things… thanks for your help.