This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use JQuery to extend forms automatically
- Loading branch information
Showing
3 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* For fields repeated as list items */ | ||
|
||
function autoduplicate() { | ||
var new_li = $( this ).clone( true ); | ||
$( new_li ).find( "label" ).attr( "for", function(index, value) { | ||
return value.replace(/-(\d+)(-\w+)?$/, function(str, p1, p2, offset, s) { | ||
if ( p2 ) { | ||
return '-' + (Number(p1) + 1) + p2; | ||
} | ||
return '-' + (Number(p1) + 1); | ||
}); | ||
}); | ||
$( new_li ).find( ":input" ).attr( "id", function(index, value) { | ||
return value.replace(/-(\d+)(-\w+)?$/, function(str, p1, p2, offset, s) { | ||
if ( p2 ) { | ||
return '-' + (Number(p1) + 1) + p2; | ||
} | ||
return '-' + (Number(p1) + 1); | ||
}); | ||
}); | ||
$( new_li ).find( ":input" ).attr( "name", function(index, value) { | ||
return value.replace(/-(\d+)(-\w+)?$/, function(str, p1, p2, offset, s) { | ||
if ( p2 ) { | ||
return '-' + (Number(p1) + 1) + p2; | ||
} | ||
return '-' + (Number(p1) + 1); | ||
}); | ||
}); | ||
$( new_li ).find( ":input" ).val(function() {return this.defaultValue}); | ||
$( new_li ).one( "change", autoduplicate ); | ||
$( this ).after( new_li ); | ||
} | ||
|
||
$( ".form-list > li:last-child" ) | ||
.one( "change", autoduplicate ); | ||
|
||
$( "input[list='keyword-list']" ).parent().filter(":last-child") | ||
.one( "change", autoduplicate ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters