Web Images Videos Maps News Shopping Google Mail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Adding a delete confirmation
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Matt Aimonetti  
View profile   Translate to Translated (View Original)
 More options 25 Jan 2008, 01:34
From: "Matt Aimonetti" <mattaimone...@gmail.com>
Date: Thu, 24 Jan 2008 17:34:54 -0800
Local: Fri 25 Jan 2008 01:34
Subject: Re: Adding a delete confirmation

Remote.DeleteLink = Behavior.create(Remote.Base, {
  onclick : function() {
    var options = Object.extend({ url : this.element.href, method : 'delete'

}, this.options);

    if (confirm('Are you sure?')){
      return this._makeRequest(options);
    }else{
      return false;
    }
  }

});

don't change your route, a delete action should not be a GET but a DELETE.

I'm sure my code could be cleaned up by extending Remote.Link but oh well,
this was a quick hack.

-Matt

On 1/24/08, KJoyner <K...@kjoyner.com> wrote:

> I am trying to use Low Pro to add a delete confirmation. In my
> controller, I have added a delete and a destroy action. These content
> of these actions are:

> def delete
>   @item = Item.find( params[ :id ] )
> end

> def destroy

>   @item = Item.find( params[ :id ] )
>   item.destroy

>   redirect_to items_path
> end

> In the routes, I add a delete route to items by:

> map.resources :items, :member => { :delete => :get }

> I then have a view where I add a delete link like this (also using
> haml):

> = link_to "delete", delete_item_path( item ), :class => 'delete'

> All of this works when I have javascript disabled. Now I am trying to
> add a behavior that will do the confirmation in javascript and if
> confirmed then redirect to the destroy action. I am trying to do this
> as follows but it is not working.

> Remote.Delete = Behavior.create( Remote.Base, {
>   onclick: function( event ) {
>     if ( confirm( 'Are you sure?'  ) ) {
>       var destroy_url = this.element.href.gsub( '/delete$', '' );
>       options = Object.extend( { url: destroy_url, method: 'delete' },
> this.options );
>       return this._makeRequest( options )
>     }
>     return false;
>   }
> });

> Event.addBehavior( {
>   '.delete' : Remote.Delete
> });

> The onclick gets executed but it is not working correctly. Any help
> would be appriciated.

> Thanks,

> -- Ken


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google