Adding a js function to a form Cancel button

SteveX
SteveX
@ultrajam
12 years ago
2,584 posts
I want to add different javascript to the cancel button.

It works fine in a modal, but my form is ajaxed in and I need to run a different js function when the Cancel button is clicked.

It looks like the only js option for the cancel button is to close a simple-modal.

Is there any other way to add a js function to the cancel button during form creation?

Thanks

line 3370 of form.php:

   // and cancel button
    if ($cancel_value || $cancel_url) {
        if (!$cancel_value) {
            $cancel_value = $_lang['jrCore'][2];
        }
        if ($cancel_url == 'referrer') {
            $cancel_url = jrCore_get_local_referrer();
        }
        if ($cancel_url == '$.modal.close();') {
            $html .= '  ';
        }
        elseif (jrCore_checktype($cancel_url, 'url')) {
            $html .= '  ';
        }
        else {
            $cancel_url = jrCore_get_last_history_url();
            $html .= '  ';
        }

What I want to be able to do is:
    $cancel = "myModule_update_div();";
    $_tmp = array(
        'submit_value' => '13,
        'cancel'       => $cancel,
        'values'       => $_rt
    );
    jrCore_form_create($_tmp);



--
¯\_(ツ)_/¯ 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: 01/19/14 04:27:56PM
michael
@michael
12 years ago
7,799 posts
SteveX:
What I want to be able to do is:
    $cancel = "myModule_update_div();";
    $_tmp = array(
        'submit_value' => '13,
        'cancel'       => $cancel,
        'values'       => $_rt
    );
    jrCore_form_create($_tmp);

would this work?
* define a function for what you want to do on the cancel and call that function

myModule_my_cancel_func()
    $cancel = "myModule_update_div();";
    $_tmp = array(
        'submit_value' => '13,
        'cancel'       => myModule_my_cancel_func(),
        'values'       => $_rt
    );
    jrCore_form_create($_tmp);
michael
@michael
12 years ago
7,799 posts
Ignore my answer above, It is what your trying to do but can't.

How would you like line 3370 of form.php to look? Better than me guessing at what needs to be done.
SteveX
SteveX
@ultrajam
12 years ago
2,584 posts
The problem is that without being able to specify an onclick, you can control what happens on form submit in the submit save php function, and when you have done that you find that you are stuck with a choice of a broken cancel button, or no cancel button at all.

I guess it would be another elseif for any js function to be placed in the onclick:
elseif (isset($cancel_url) && strlen($cancel_url) > 1) {
            $html .= '   input type="button" id="' . $_form['form_params']['name'] . '_cancel" class="form_button" value="' . $cancel_value . '" onclick="' . $cancel_url . '" ';
        }
I've taken out the for the input - the forum didn't print the inputs in the code block in my first post.


--
¯\_(ツ)_/¯ 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
12 years ago
7,799 posts
Should be in next release.
SteveX
SteveX
@ultrajam
12 years ago
2,584 posts
Thanks Michael!


--
¯\_(ツ)_/¯ 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