6b5a68d41436ce28831a0e0ca6bcd124

This is some javascript which flags an element (and hides it from the current view) to be deleted when a form is submitted. Thanks for the help! I've learned a lot from my previous posts as well. This is a great community!

application.js

1
2
3
4
5
6
7
8
9
10
function mark_for_destroy(element) {
  $(element).next('.should_destroy').value = 1;
  $(element).up('.phone').hide();
}

function e_mark_for_destroy(element) {
  $(element).next('.should_destroy').value = 1;
  $(element).up('.email').hide();
}

Refactorings

No refactoring yet !

626b9b038d946d6786dd14861ecfde47

yaleman

October 18, 2007, October 18, 2007 08:49, permalink

3 ratings. Login to rate!

now you can feed it .phone or .email or any other type you'd like :)

1
2
3
4
function mark_for_destroy(element,type) {
  $(element).next('.should_destroy').value = 1;
  $(element).up(type).hide();
}
6b5a68d41436ce28831a0e0ca6bcd124

Etandrib

October 18, 2007, October 18, 2007 15:34, permalink

No rating. Login to rate!

This works great. For other people following the call needs to look something similar to what I have below.

_email.rhtml

1
<%= link_to_function "Remove", "mark_for_destroy(this,'.email')" %>

Your refactoring





Format Copy from initial code

or Cancel