jrCore_page_set_no_header_or_footer breaks javascript added to form in modal

SteveX
SteveX
@ultrajam
6 years ago
2,583 posts
I have an item form which loads in a modal window.

If I use jrCore_page_set_no_header_or_footer() in the item form everything looks great but the javascript in the form doesn't work (image upload, chained selects, etc). Inline js such as the help button slider continues to work fine though.

There aren't any errors, I think the javascript just isn't included in the page.

Is there a convenient way to remove the header and footer but for javascript_ready_function form js to still work?

Thanks!


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

updated by @ultrajam: 06/30/18 12:47:16PM
michael
@michael
6 years ago
7,692 posts
yes. Why yes there is. :)
jrCore_page_set_meta_header_only();

--edit--
You might find this useful too perhaps:
    $html = "
    <script>
        $(document).ajaxSuccess(function (event, request, settings, data) {
            if(typeof(data.form_name) != \"undefined\" && data.form_name == 'ajax_create_save') {
                jrSeminar_load_calendar('seminar_calendar_box', 'current');
            }
        });
    </script>";
    jrCore_page_custom($html);

    jrCore_page_display();

"After that bit of ajax finishes loading, fire this function......." because on.document.ready doesnt work for ajax loaded content. send the form name back with the json_response:

......
    jrCore_form_delete_session();
    jrUser_reset_cache($_user['_user_id']);
    $_resp = array(
        'form_name'   => 'ajax_create_save',
        'success'     => 1,
        'success_msg' => "the new seminar got created"
    );

    jrCore_json_response($_resp);

updated by @michael: 03/30/18 08:38:52PM
SteveX
SteveX
@ultrajam
6 years ago
2,583 posts
That's great, thank you Michael! And the form examples are very useful too.

The problem that I have now is that I can no longer close the modal with $.modal.close();

Using jrCore_page_set_no_header_or_footer() I can close the modal, but not when I use jrCore_page_set_meta_header_only()

Any idea what might be going on there, or possible workaround?

Thanks


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
michael
@michael
6 years ago
7,692 posts
just guessing.

Maybe open the modal and store it to a variable:
 var the_modal = $.modal.open()
Then when you want to close it use the variables close function
the_modal.close()
Guess is that the meta include includes another different modal and it doesnt know about the parent modal that it is contained in, so the child modal is closing when you want the parent to close.

Or in the ajax call that brought in the form, once the form is saved, fire another function that closes the window.

Or dont put it in a modal, put it into the page and then re-add the contents after the save is completed or the cancel is clicked.
updated by @michael: 03/31/18 08:26:38PM
SteveX
SteveX
@ultrajam
6 years ago
2,583 posts
I've tried every way around.

I think I have found what's causing it though.

If I load the parent page in the browser, then delete the contents of jrCore/js/jquery-1.12.4.min.js and then open the modal everything works fine.

So I think it's the 2nd copy of jQuery 1.12.4 which breaks the modal. I've tried removing everything else one bit at a time, but that's the only thing which makes a difference.

Why it should break the modal but all other js works fine I don't know.

Any idea how I can get around that?

Thanks


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
SteveX
SteveX
@ultrajam
6 years ago
2,583 posts
I think I have a solution...


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
SteveX
SteveX
@ultrajam
6 years ago
2,583 posts
    $html = "
    <script>
    	secondcopyjquery = jQuery.noConflict( true );
    </script>";
    jrCore_page_custom($html);
With that in the forms to appear in the modal everything seems fine :)

The last example on this page is for loading two different versions of jQuery:
https://api.jquery.com/jquery.noconflict/


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

Tags