onclick on submitToRemote and form validation?

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

onclick on submitToRemote and form validation?

Steven Devijver
Hey,

The onclick attribute on submitToRemote doesn't seem to get fired.

Prototype can't manage it either:

        Event.observe(
                'submitButton',
                onclick,
                function(e) {
                        alert("Gotcha!");
                        Event.stop(e);
                },
                true);



Which hook should I use then to intercept a form submit and cancel it
if required?

Thanks

Steven

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: onclick on submitToRemote and form validation?

Siegfried Puchbauer
For markup like that:

<form id="myform" action="..." ... >
...

<input type="submit" id="submitButton" value="Send" ... />
</form>

You can use:
Event.observe(window,'load', function() { // wait 'til DOM is ready
      $('myform').observe('submit', function(e) { .... Event.stop(e); ... return false; });
      $('submitButton').observe('click', function(e) { .... Event.stop(e); ... return false; });
});

hth

Cheers, sigi

On 11/2/07, Steven Devijver <[hidden email]> wrote:
Hey,

The onclick attribute on submitToRemote doesn't seem to get fired.

Prototype can't manage it either:

        Event.observe(
                'submitButton',
                onclick,
                function(e) {
                        alert("Gotcha!");
                        Event.stop(e);
                },
                true);



Which hook should I use then to intercept a form submit and cancel it
if required?

Thanks

Steven

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email




--
_______________________
Siegfried Puchbauer
http://siegfried.puchbauer.com/
Reply | Threaded
Open this post in threaded view
|

Re: onclick on submitToRemote and form validation?

Steven Devijver
I'm hooked into the click event now thanks to Event.observe().
However, Event.stop(e) doesn't seem to have any effect.

Any ideas?

Thanks

Steven

On 11/2/07, Siegfried Puchbauer <[hidden email]> wrote:

> For markup like that:
>
> <form id="myform" action="..." ... >
> ...
>
> <input type="submit" id="submitButton" value="Send" ... />
> </form>
>
> You can use:
> Event.observe(window,'load', function() { // wait 'til DOM is ready
>       $('myform').observe('submit', function(e) { .... Event.stop(e); ...
> return false; });
>       $('submitButton').observe('click', function(e) { ....
> Event.stop(e); ... return false; });
>  });
>
> hth
>
> Cheers, sigi
>
>
> On 11/2/07, Steven Devijver <[hidden email]> wrote:
> >
> > Hey,
> >
> > The onclick attribute on submitToRemote doesn't seem to get fired.
> >
> > Prototype can't manage it either:
> >
> >         Event.observe(
> >                 'submitButton',
> >                 onclick,
> >                 function(e) {
> >                         alert("Gotcha!");
> >                         Event.stop(e);
> >                 },
> >                 true);
> >
> >
> >
> > Which hook should I use then to intercept a form submit and cancel it
> > if required?
> >
> > Thanks
> >
> > Steven
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
>
>
> --
> _______________________
> Siegfried Puchbauer
> http://siegfried.puchbauer.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: onclick on submitToRemote and form validation?

Steven Devijver
Hmmm,

A small experiment learns that the event handler in the onclick
attribute has precedence over any event handlers registered with
Event.observe().

Unfortunately the submitToRemote tag uses the onclick attribute so
there is effectively no way to prevent the form from being submitted.

A possible solution would be to let the submitToRemote tag use
Event.observe() and maybe so not by default but via configuration.

Any thoughts on that?

Thanks

Steven

On 11/2/07, Steven Devijver <[hidden email]> wrote:

> I'm hooked into the click event now thanks to Event.observe().
> However, Event.stop(e) doesn't seem to have any effect.
>
> Any ideas?
>
> Thanks
>
> Steven
>
> On 11/2/07, Siegfried Puchbauer <[hidden email]> wrote:
> > For markup like that:
> >
> > <form id="myform" action="..." ... >
> > ...
> >
> > <input type="submit" id="submitButton" value="Send" ... />
> > </form>
> >
> > You can use:
> > Event.observe(window,'load', function() { // wait 'til DOM is ready
> >       $('myform').observe('submit', function(e) { .... Event.stop(e); ...
> > return false; });
> >       $('submitButton').observe('click', function(e) { ....
> > Event.stop(e); ... return false; });
> >  });
> >
> > hth
> >
> > Cheers, sigi
> >
> >
> > On 11/2/07, Steven Devijver <[hidden email]> wrote:
> > >
> > > Hey,
> > >
> > > The onclick attribute on submitToRemote doesn't seem to get fired.
> > >
> > > Prototype can't manage it either:
> > >
> > >         Event.observe(
> > >                 'submitButton',
> > >                 onclick,
> > >                 function(e) {
> > >                         alert("Gotcha!");
> > >                         Event.stop(e);
> > >                 },
> > >                 true);
> > >
> > >
> > >
> > > Which hook should I use then to intercept a form submit and cancel it
> > > if required?
> > >
> > > Thanks
> > >
> > > Steven
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe from this list please visit:
> > >
> > >     http://xircles.codehaus.org/manage_email
> > >
> > >
> >
> >
> >
> > --
> > _______________________
> > Siegfried Puchbauer
> > http://siegfried.puchbauer.com/
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: onclick on submitToRemote and form validation?

Siegfried Puchbauer
If you return false in the function called by the onclick attribute, the event gets cancelled.
 
Cheers, sigi

 
On 11/2/07, Steven Devijver <[hidden email]> wrote:
Hmmm,

A small experiment learns that the event handler in the onclick
attribute has precedence over any event handlers registered with
Event.observe().

Unfortunately the submitToRemote tag uses the onclick attribute so
there is effectively no way to prevent the form from being submitted.

A possible solution would be to let the submitToRemote tag use
Event.observe() and maybe so not by default but via configuration.

Any thoughts on that?

Thanks

Steven

On 11/2/07, Steven Devijver <[hidden email]> wrote:

> I'm hooked into the click event now thanks to Event.observe().
> However, Event.stop(e) doesn't seem to have any effect.
>
> Any ideas?
>
> Thanks
>
> Steven
>
> On 11/2/07, Siegfried Puchbauer <[hidden email]> wrote:
> > For markup like that:
> >
> > <form id="myform" action="..." ... >
> > ...
> >
> > <input type="submit" id="submitButton" value="Send" ... />
> > </form>
> >
> > You can use:
> > Event.observe (window,'load', function() { // wait 'til DOM is ready
> >       $('myform').observe('submit', function(e) { .... Event.stop(e); ...
> > return false; });
> >       $('submitButton').observe('click', function(e) { ....
> > Event.stop(e); ... return false; });
> >  });
> >
> > hth
> >
> > Cheers, sigi
> >
> >
> > On 11/2/07, Steven Devijver <[hidden email]> wrote:
> > >
> > > Hey,
> > >
> > > The onclick attribute on submitToRemote doesn't seem to get fired.
> > >
> > > Prototype can't manage it either:
> > >
> > >         Event.observe(
> > >                 'submitButton',
> > >                 onclick,
> > >                 function(e) {
> > >                         alert("Gotcha!");
> > >                         Event.stop(e);
> > >                 },
> > >                 true);
> > >
> > >
> > >
> > > Which hook should I use then to intercept a form submit and cancel it
> > > if required?
> > >
> > > Thanks
> > >
> > > Steven
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe from this list please visit:
> > >
> > >     http://xircles.codehaus.org/manage_email
> > >
> > >
> >
> >
> >
> > --
> > _______________________
> > Siegfried Puchbauer
> > http://siegfried.puchbauer.com/
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email




--
_______________________
Siegfried Puchbauer
http://siegfried.puchbauer.com/
Reply | Threaded
Open this post in threaded view
|

Do custom Validators Work on grails-1.0-rc1?

chris8185
I have a simple domain class with the following code:

class Location{  
    Long ownerId  // comes from the Person table
    Long buildingId  // comes from the Building table
    Long roomId // comes from the Room table

    static constraints = {
        ownerId()
        buildingId(nullable:true)
        roomId(
            validator: {
                val, obj ->
                // if building id is provided then room id is required
                if(obj.properties['buildingId'] != null){
                    if(val == null){
                        return ['building.room.empty']
                    }
                }
            }
            , nullable:true
        )
    }
}

I opened a grails console and setup the following test:

def location = new Location()
location.ownerId = 1
location.buildingId = 1
location.roomId = null
location.save()
assert location.id == null

My assertion fails and the domain class saves successfully.  It doesn't
appear that the custom validation is ever called.

Does anyone know if this is something that has already been addressed by
a new version of grails?


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: onclick on submitToRemote and form validation?

Steven Devijver
In reply to this post by Siegfried Puchbauer
It doesn't make a difference what you return because the Ajax call
always happens before validation. There seems no way to change that.

Steven

On 11/2/07, Siegfried Puchbauer <[hidden email]> wrote:

> If you return false in the function called by the onclick attribute, the
> event gets cancelled.
>
>
> Cheers, sigi
>
>
> On 11/2/07, Steven Devijver <[hidden email]> wrote:
> > Hmmm,
> >
> > A small experiment learns that the event handler in the onclick
> > attribute has precedence over any event handlers registered with
> > Event.observe().
> >
> > Unfortunately the submitToRemote tag uses the onclick attribute so
> > there is effectively no way to prevent the form from being submitted.
> >
> > A possible solution would be to let the submitToRemote tag use
> > Event.observe() and maybe so not by default but via configuration.
> >
> > Any thoughts on that?
> >
> > Thanks
> >
> > Steven
> >
> > On 11/2/07, Steven Devijver <[hidden email] > wrote:
> > > I'm hooked into the click event now thanks to Event.observe().
> > > However, Event.stop(e) doesn't seem to have any effect.
> > >
> > > Any ideas?
> > >
> > > Thanks
> > >
> > > Steven
> > >
> > > On 11/2/07, Siegfried Puchbauer <[hidden email]> wrote:
> > > > For markup like that:
> > > >
> > > > <form id="myform" action="..." ... >
> > > > ...
> > > >
> > > > <input type="submit" id="submitButton" value="Send" ... />
> > > > </form>
> > > >
> > > > You can use:
> > > > Event.observe (window,'load', function() { // wait 'til DOM is ready
> > > >       $('myform').observe('submit', function(e) { .... Event.stop(e);
> ...
> > > > return false; });
> > > >       $('submitButton').observe('click', function(e)
> { ....
> > > > Event.stop(e); ... return false; });
> > > >  });
> > > >
> > > > hth
> > > >
> > > > Cheers, sigi
> > > >
> > > >
> > > > On 11/2/07, Steven Devijver < [hidden email]> wrote:
> > > > >
> > > > > Hey,
> > > > >
> > > > > The onclick attribute on submitToRemote doesn't seem to get fired.
> > > > >
> > > > > Prototype can't manage it either:
> > > > >
> > > > >         Event.observe(
> > > > >                 'submitButton',
> > > > >                 onclick,
> > > > >                 function(e) {
> > > > >                         alert("Gotcha!");
> > > > >                         Event.stop(e);
> > > > >                 },
> > > > >                 true);
> > > > >
> > > > >
> > > > >
> > > > > Which hook should I use then to intercept a form submit and cancel
> it
> > > > > if required?
> > > > >
> > > > > Thanks
> > > > >
> > > > > Steven
> > > > >
> > > > >
> > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe from this list please visit:
> > > > >
> > > > >     http://xircles.codehaus.org/manage_email
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > _______________________
> > > > Siegfried Puchbauer
> > > > http://siegfried.puchbauer.com/
> > >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >    http://xircles.codehaus.org/manage_email
> >
> >
>
>
>
> --
> _______________________
> Siegfried Puchbauer
> http://siegfried.puchbauer.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: onclick on submitToRemote and form validation?

Siegfried Puchbauer
If you do an Ajax Call, you always have to cancel the form submission.

Cheers, sigi

On Nov 6, 2007 12:52 PM, Steven Devijver <[hidden email]> wrote:
It doesn't make a difference what you return because the Ajax call
always happens before validation. There seems no way to change that.

Steven

On 11/2/07, Siegfried Puchbauer <[hidden email]> wrote:

> If you return false in the function called by the onclick attribute, the
> event gets cancelled.
>
>
> Cheers, sigi
>
>
> On 11/2/07, Steven Devijver <[hidden email]> wrote:
> > Hmmm,
> >
> > A small experiment learns that the event handler in the onclick
> > attribute has precedence over any event handlers registered with
> > Event.observe().
> >
> > Unfortunately the submitToRemote tag uses the onclick attribute so
> > there is effectively no way to prevent the form from being submitted.
> >
> > A possible solution would be to let the submitToRemote tag use

> > Event.observe() and maybe so not by default but via configuration.
> >
> > Any thoughts on that?
> >
> > Thanks
> >
> > Steven
> >
> > On 11/2/07, Steven Devijver <[hidden email] > wrote:
> > > I'm hooked into the click event now thanks to Event.observe().
> > > However, Event.stop(e) doesn't seem to have any effect.
> > >
> > > Any ideas?
> > >
> > > Thanks
> > >
> > > Steven
> > >
> > > On 11/2/07, Siegfried Puchbauer <[hidden email]> wrote:
> > > > For markup like that:
> > > >
> > > > <form id="myform" action="..." ... >
> > > > ...
> > > >
> > > > <input type="submit" id="submitButton" value="Send" ... />
> > > > </form>
> > > >
> > > > You can use:
> > > > Event.observe (window,'load', function() { // wait 'til DOM is ready
> > > >       $('myform').observe('submit', function(e) { .... Event.stop(e);
> ...
> > > > return false; });
> > > >       $('submitButton').observe('click', function(e)
> { ....
> > > > Event.stop(e); ... return false; });
> > > >  });
> > > >
> > > > hth
> > > >
> > > > Cheers, sigi
> > > >
> > > >
> > > > On 11/2/07, Steven Devijver < [hidden email]> wrote:
> > > > >
> > > > > Hey,
> > > > >
> > > > > The onclick attribute on submitToRemote doesn't seem to get fired.
> > > > >
> > > > > Prototype can't manage it either:
> > > > >
> > > > >         Event.observe(
> > > > >                 'submitButton',
> > > > >                 onclick,
> > > > >                 function(e) {
> > > > >                         alert("Gotcha!");
> > > > >                         Event.stop(e);
> > > > >                 },
> > > > >                 true);
> > > > >
> > > > >
> > > > >
> > > > > Which hook should I use then to intercept a form submit and cancel
> it
> > > > > if required?
> > > > >
> > > > > Thanks
> > > > >
> > > > > Steven
> > > > >
> > > > >
> > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe from this list please visit:
> > > > >
> > > > >     http://xircles.codehaus.org/manage_email
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > _______________________
> > > > Siegfried Puchbauer
> > > > http://siegfried.puchbauer.com/
> > >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
>
>
> --
> _______________________
> Siegfried Puchbauer
> http://siegfried.puchbauer.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email




--
_______________________
Siegfried Puchbauer
http://siegfried.puchbauer.com/