submit form with context from js

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

submit form with context from js

George Christman
Hello, I'm using 5.4 and a custom mixin on my submit actions which is
used to trigger the bootstrap modal popup. My popup does nothing other
than provide warnings to the user prior to form submission. I'm trying
to figure out how to submit the form from my modal popup with the
original submit buttons context. When original submit button is
clicked, I'd like to somehow pass in the context to modal so I can
reconstruct the new submit action.

Current JS code

define(["jquery", "bootstrap/modal"], function($) {
    int = function(spec) {
        var $field = $("#" + spec.id);

        $field.bind("click", function(e) {
            e.preventDefault();
            $("#" + spec.id + "Modal").modal();
        });
    };
    return int;
});

Can someone point me in the correct direction?

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: submit form with context from js

Lance Java
You could use 2 buttons (one hidden).
Hide the original form submit button and show a button that fires the
modal. The modal somehow fires a click event on the hidden submit button.
Reply | Threaded
Open this post in threaded view
|

Re: submit form with context from js

George Christman
I guess that would work, I wish there was a way to reconstruct the
original submit button in js.

On Wed, Dec 18, 2013 at 9:56 AM, Lance Java <[hidden email]> wrote:
> You could use 2 buttons (one hidden).
> Hide the original form submit button and show a button that fires the
> modal. The modal somehow fires a click event on the hidden submit button.



--
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: submit form with context from js

Taha Hafeez Siddiqi
If there is only one submit button, you can also use form's own context parameter. that way you just have to call form.submit() from the javascript.


On Dec 18, 2013, at 8:46 PM, George Christman wrote:

> I guess that would work, I wish there was a way to reconstruct the
> original submit button in js.
>
> On Wed, Dec 18, 2013 at 9:56 AM, Lance Java <[hidden email]> wrote:
>> You could use 2 buttons (one hidden).
>> Hide the original form submit button and show a button that fires the
>> modal. The modal somehow fires a click event on the hidden submit button.
>
>
>
> --
> George Christman
> www.CarDaddy.com
> P.O. Box 735
> Johnstown, New York
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

Reply | Threaded
Open this post in threaded view
|

Re: submit form with context from js

George Christman
No, there is unfortunately 4 submit buttons.  :(

On Wed, Dec 18, 2013 at 10:30 AM, Taha Siddiqi <[hidden email]> wrote:

> If there is only one submit button, you can also use form's own context parameter. that way you just have to call form.submit() from the javascript.
>
>
> On Dec 18, 2013, at 8:46 PM, George Christman wrote:
>
>> I guess that would work, I wish there was a way to reconstruct the
>> original submit button in js.
>>
>> On Wed, Dec 18, 2013 at 9:56 AM, Lance Java <[hidden email]> wrote:
>>> You could use 2 buttons (one hidden).
>>> Hide the original form submit button and show a button that fires the
>>> modal. The modal somehow fires a click event on the hidden submit button.
>>
>>
>>
>> --
>> George Christman
>> www.CarDaddy.com
>> P.O. Box 735
>> Johnstown, New York
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>



--
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: submit form with context from js

George Christman
In reply to this post by Taha Hafeez Siddiqi
Taha, firing $("#form").trigger('submit'); seems to remember my
original submit action. Should I be wary of this with other browsers?

example

define(["jquery", "bootstrap/modal"], function($) {
    int = function(spec) {
        var $field = $("#" + spec.id);

        $field.bind("click", function(e) {
            e.preventDefault();
            $("#" + spec.id + "Modal").modal();


            $("#modalsubmit-" + spec.id).bind("click", function(e) {
                $("#" + spec.formId).trigger('submit');
            });
        });
    };
    return int;
});

On Wed, Dec 18, 2013 at 10:30 AM, Taha Siddiqi <[hidden email]> wrote:

> If there is only one submit button, you can also use form's own context parameter. that way you just have to call form.submit() from the javascript.
>
>
> On Dec 18, 2013, at 8:46 PM, George Christman wrote:
>
>> I guess that would work, I wish there was a way to reconstruct the
>> original submit button in js.
>>
>> On Wed, Dec 18, 2013 at 9:56 AM, Lance Java <[hidden email]> wrote:
>>> You could use 2 buttons (one hidden).
>>> Hide the original form submit button and show a button that fires the
>>> modal. The modal somehow fires a click event on the hidden submit button.
>>
>>
>>
>> --
>> George Christman
>> www.CarDaddy.com
>> P.O. Box 735
>> Johnstown, New York
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>



--
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: submit form with context from js

Taha Hafeez Siddiqi
If I am using jQuery, I won't be too much worried about it.

BTW nice catch !!

On Dec 18, 2013, at 9:34 PM, George Christman wrote:

> Taha, firing $("#form").trigger('submit'); seems to remember my
> original submit action. Should I be wary of this with other browsers?
>
> example
>
> define(["jquery", "bootstrap/modal"], function($) {
>    int = function(spec) {
>        var $field = $("#" + spec.id);
>
>        $field.bind("click", function(e) {
>            e.preventDefault();
>            $("#" + spec.id + "Modal").modal();
>
>
>            $("#modalsubmit-" + spec.id).bind("click", function(e) {
>                $("#" + spec.formId).trigger('submit');
>            });
>        });
>    };
>    return int;
> });
>
> On Wed, Dec 18, 2013 at 10:30 AM, Taha Siddiqi <[hidden email]> wrote:
>> If there is only one submit button, you can also use form's own context parameter. that way you just have to call form.submit() from the javascript.
>>
>>
>> On Dec 18, 2013, at 8:46 PM, George Christman wrote:
>>
>>> I guess that would work, I wish there was a way to reconstruct the
>>> original submit button in js.
>>>
>>> On Wed, Dec 18, 2013 at 9:56 AM, Lance Java <[hidden email]> wrote:
>>>> You could use 2 buttons (one hidden).
>>>> Hide the original form submit button and show a button that fires the
>>>> modal. The modal somehow fires a click event on the hidden submit button.
>>>
>>>
>>>
>>> --
>>> George Christman
>>> www.CarDaddy.com
>>> P.O. Box 735
>>> Johnstown, New York
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>
>
>
> --
> George Christman
> www.CarDaddy.com
> P.O. Box 735
> Johnstown, New York
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>