Skip to content

Instantly share code, notes, and snippets.

@neokoenig
Created March 25, 2011 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neokoenig/886718 to your computer and use it in GitHub Desktop.
Save neokoenig/886718 to your computer and use it in GitHub Desktop.
<!--- Dynamic Email Field Template--->
<div id="email-templates" class=" clearfix" style="display: none ;">
<div id="::FIELD1::" class="emailtemplate clearfix">
<div class="span-11">
<div class="field">
<label for="contact-emailaddresses-::FIELD2::-email">Email Address</label>
<input type="text" value="" size="62" name="contact[emailaddresses][::FIELD12::][email]" maxlength="500" id="contact-emailaddresses-::FIELD3::-email" class="email">
</div>
</div>
<div class="span-3">
<div class="field">
<label for="contact-emailaddresses-::FIELD4::-type">Type</label>
<select name="contact[emailaddresses][::FIELD5::][type]" id="contact-emailaddresses-::FIELD6::-type">
<option value="Work">Work</option>
<option value="Home">Home</option>
</select>
</div>
</div>
<div class="span-3">
<label for="contact-emailaddresses-::FIELD7::-preferred" class="checkboxLabel">Preferred</label>
<div class="checkbox">
<input type="checkbox" value="1" name="contact[emailaddresses][::FIELD8::][preferred]" id="contact-emailaddresses-::FIELD9::-preferred" class="checkbox">
<input type="hidden" value="0" name="contact[emailaddresses][::FIELD10::][preferred]($checkbox)" id="contact-emailaddresses-::FIELD11::-preferred-checkbox">
</div>
</div>
<div class="span-3 last prepend-top">
<p><a class="button negative removeemail" href="">Remove</a></p>
</div>
</div>
</div>
<script>
// Another bit of JS nicked from Ben Nadel.
// When the DOM has loaded, init the form link.
$(
function addemail(){
var jAddNewRecipient = $( "#addnewemail" );
jAddNewRecipient
.attr( "href", "javascript:void( 0 )" )
.click(
function( objEvent ){
AddNewUpload();
objEvent.preventDefault();
return( false );
}
);
}
)
$('.removeemail').live('click',function() {
$(this).parents("div.emailtemplate:first").remove();
return( false );
});
function AddNewUpload(){
var jFilesContainer = $( "#emails" );
var jUploadTemplate = $( "#email-templates div.emailtemplate" );
var jUpload = jUploadTemplate.clone();
var strNewHTML = jUpload.html();
var intNewFileCount = (jFilesContainer.find( "div.emailtemplate" ).length + 1);
jUpload.attr( "id", ("emailedit[" + intNewFileCount + "]") );
strNewHTML = strNewHTML
.replace(
new RegExp( "::FIELD1::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD2::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD3::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD4::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD5::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD6::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD7::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD8::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD9::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD10::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD11::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD12::", "i" ),
intNewFileCount
)
;
jUpload.html( strNewHTML );
jFilesContainer.append( jUpload );
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment