Modify the Plugin to use dynamic naming for the form fields added
I am using the Following Plugin, but every time i create a new fom field, it does not increment the field name, how can i fix this plugin, can't change because we are way ahead with it
/*
Title: Cozeit More plugin by Yasir Atabani
Documentation: na
Author: Yasir O. Atabani
Website: http://www.cozeit.com
Twitter: @yatabani
MIT License, https://github.com/cozeit/czMore/blob/master/LICENSE.md
*/
(function ($, undefined)
$.fn.czMore = function (options)
//Set defauls for the control
var defaults =
max: 5,
min: 0,
onLoad: null,
onAdd: null,
onDelete: null,
styleOverride: false,
;
//Update unset options with defaults if needed
var options = $.extend(defaults, options);
$(this).bind("onAdd", function (event, data)
options.onAdd.call(event, data);
);
$(this).bind("onLoad", function (event, data)
options.onLoad.call(event, data);
);
$(this).bind("onDelete", function (event, data)
options.onDelete.call(event, data);
);
//Executing functionality on all selected elements
return this.each(function ()
var obj = $(this);
var i = obj.children(".recordset").length;
var divPlus = '<div id="btnPlus" class="btnPlus"/>';
var count = '<input id="' + this.id + '_czMore_txtCount" name="' + this.id + '_czMore_txtCount" type="hidden" value="0" size="5" />';
obj.before(count);
var recordset = obj.children("#first");
obj.after(divPlus);
var set = recordset.children(".recordset").children().first();
var btnPlus = obj.siblings("#btnPlus");
if(!options.styleOverride)
btnPlus.css(
'float': 'right',
'border': '0px',
'background-image': 'url("/default/includes/themes/images/add.png")',
'background-position': 'center center',
'background-repeat': 'no-repeat',
'height': '25px',
'width': '25px',
'cursor': 'pointer',
);
if (recordset.length)
obj.siblings("#btnPlus").click(function ()
var i = obj.children(".recordset").length;
var item = recordset.clone().html();
i++;
item = item.replace(/[([0-9]d0)]/g, "[" + i + "]");
item = item.replace(/_([0-9]d0)_/g, "_" + i + "_");
//$(element).html(item);
//item = $(item).children().first();
//item = $(item).parent();
obj.append(item);
loadMinus(obj.children().last());
minusClick(obj.children().last());
if (options.onAdd != null)
obj.trigger("onAdd", i);
obj.siblings("input[name$='czMore_txtCount']").val(i);
return false;
);
recordset.remove();
for (var j = 0; j <= i; j++)
loadMinus(obj.children()[j]);
minusClick(obj.children()[j]);
if (options.onAdd != null)
obj.trigger("onAdd", j);
if (options.onLoad != null)
obj.trigger("onLoad", i);
//obj.bind("onAdd", function (event, data)
//If you had passed anything in your trigger function, you can grab it using the second parameter in the callback function.
//);
function resetNumbering()
$(obj).children(".recordset").each(function (index, element)
$(element).find('input:text, input:password, input:file, select, textarea').each(function()
old_name = this.name;
new_name = old_name.replace(/_([0-9]d0)_/g, "_" + (index + 1) + "_");
this.id = this.name = new_name;
//alert(this.name);
);
index++
minusClick(element);
);
function loadMinus(recordset)
var divMinus = '<div id="btnMinus" class="btnMinus" />';
$(recordset).children().first().before(divMinus);
var btnMinus = $(recordset).children("#btnMinus");
if(!options.styleOverride)
btnMinus.css(
'float': 'right',
'border': '0px',
'background-image': 'url("/default/includes/themes/images/remove.png")',
'background-position': 'center center',
'background-repeat': 'no-repeat',
'height': '25px',
'width': '25px',
'cursor': 'poitnter',
);
function minusClick(recordset)
$(recordset).children("#btnMinus").click(function ()
var i = obj.children(".recordset").length;
var id = $(recordset).attr("data-id")
$(recordset).remove();
resetNumbering();
obj.siblings("input[name$='czMore_txtCount']").val(obj.children(".recordset").length);
i--;
if (options.onDelete != null)
if (id != null)
obj.trigger("onDelete", id);
);
);
;
)(jQuery);
the above is the jquery code we found on the sourceforge website and tried this code, we have been using this function in other instances so trying to modify its behavior, looks like it do support dynamic naming but somehow it is not working
javascript jquery
add a comment |
I am using the Following Plugin, but every time i create a new fom field, it does not increment the field name, how can i fix this plugin, can't change because we are way ahead with it
/*
Title: Cozeit More plugin by Yasir Atabani
Documentation: na
Author: Yasir O. Atabani
Website: http://www.cozeit.com
Twitter: @yatabani
MIT License, https://github.com/cozeit/czMore/blob/master/LICENSE.md
*/
(function ($, undefined)
$.fn.czMore = function (options)
//Set defauls for the control
var defaults =
max: 5,
min: 0,
onLoad: null,
onAdd: null,
onDelete: null,
styleOverride: false,
;
//Update unset options with defaults if needed
var options = $.extend(defaults, options);
$(this).bind("onAdd", function (event, data)
options.onAdd.call(event, data);
);
$(this).bind("onLoad", function (event, data)
options.onLoad.call(event, data);
);
$(this).bind("onDelete", function (event, data)
options.onDelete.call(event, data);
);
//Executing functionality on all selected elements
return this.each(function ()
var obj = $(this);
var i = obj.children(".recordset").length;
var divPlus = '<div id="btnPlus" class="btnPlus"/>';
var count = '<input id="' + this.id + '_czMore_txtCount" name="' + this.id + '_czMore_txtCount" type="hidden" value="0" size="5" />';
obj.before(count);
var recordset = obj.children("#first");
obj.after(divPlus);
var set = recordset.children(".recordset").children().first();
var btnPlus = obj.siblings("#btnPlus");
if(!options.styleOverride)
btnPlus.css(
'float': 'right',
'border': '0px',
'background-image': 'url("/default/includes/themes/images/add.png")',
'background-position': 'center center',
'background-repeat': 'no-repeat',
'height': '25px',
'width': '25px',
'cursor': 'pointer',
);
if (recordset.length)
obj.siblings("#btnPlus").click(function ()
var i = obj.children(".recordset").length;
var item = recordset.clone().html();
i++;
item = item.replace(/[([0-9]d0)]/g, "[" + i + "]");
item = item.replace(/_([0-9]d0)_/g, "_" + i + "_");
//$(element).html(item);
//item = $(item).children().first();
//item = $(item).parent();
obj.append(item);
loadMinus(obj.children().last());
minusClick(obj.children().last());
if (options.onAdd != null)
obj.trigger("onAdd", i);
obj.siblings("input[name$='czMore_txtCount']").val(i);
return false;
);
recordset.remove();
for (var j = 0; j <= i; j++)
loadMinus(obj.children()[j]);
minusClick(obj.children()[j]);
if (options.onAdd != null)
obj.trigger("onAdd", j);
if (options.onLoad != null)
obj.trigger("onLoad", i);
//obj.bind("onAdd", function (event, data)
//If you had passed anything in your trigger function, you can grab it using the second parameter in the callback function.
//);
function resetNumbering()
$(obj).children(".recordset").each(function (index, element)
$(element).find('input:text, input:password, input:file, select, textarea').each(function()
old_name = this.name;
new_name = old_name.replace(/_([0-9]d0)_/g, "_" + (index + 1) + "_");
this.id = this.name = new_name;
//alert(this.name);
);
index++
minusClick(element);
);
function loadMinus(recordset)
var divMinus = '<div id="btnMinus" class="btnMinus" />';
$(recordset).children().first().before(divMinus);
var btnMinus = $(recordset).children("#btnMinus");
if(!options.styleOverride)
btnMinus.css(
'float': 'right',
'border': '0px',
'background-image': 'url("/default/includes/themes/images/remove.png")',
'background-position': 'center center',
'background-repeat': 'no-repeat',
'height': '25px',
'width': '25px',
'cursor': 'poitnter',
);
function minusClick(recordset)
$(recordset).children("#btnMinus").click(function ()
var i = obj.children(".recordset").length;
var id = $(recordset).attr("data-id")
$(recordset).remove();
resetNumbering();
obj.siblings("input[name$='czMore_txtCount']").val(obj.children(".recordset").length);
i--;
if (options.onDelete != null)
if (id != null)
obj.trigger("onDelete", id);
);
);
;
)(jQuery);
the above is the jquery code we found on the sourceforge website and tried this code, we have been using this function in other instances so trying to modify its behavior, looks like it do support dynamic naming but somehow it is not working
javascript jquery
add a comment |
I am using the Following Plugin, but every time i create a new fom field, it does not increment the field name, how can i fix this plugin, can't change because we are way ahead with it
/*
Title: Cozeit More plugin by Yasir Atabani
Documentation: na
Author: Yasir O. Atabani
Website: http://www.cozeit.com
Twitter: @yatabani
MIT License, https://github.com/cozeit/czMore/blob/master/LICENSE.md
*/
(function ($, undefined)
$.fn.czMore = function (options)
//Set defauls for the control
var defaults =
max: 5,
min: 0,
onLoad: null,
onAdd: null,
onDelete: null,
styleOverride: false,
;
//Update unset options with defaults if needed
var options = $.extend(defaults, options);
$(this).bind("onAdd", function (event, data)
options.onAdd.call(event, data);
);
$(this).bind("onLoad", function (event, data)
options.onLoad.call(event, data);
);
$(this).bind("onDelete", function (event, data)
options.onDelete.call(event, data);
);
//Executing functionality on all selected elements
return this.each(function ()
var obj = $(this);
var i = obj.children(".recordset").length;
var divPlus = '<div id="btnPlus" class="btnPlus"/>';
var count = '<input id="' + this.id + '_czMore_txtCount" name="' + this.id + '_czMore_txtCount" type="hidden" value="0" size="5" />';
obj.before(count);
var recordset = obj.children("#first");
obj.after(divPlus);
var set = recordset.children(".recordset").children().first();
var btnPlus = obj.siblings("#btnPlus");
if(!options.styleOverride)
btnPlus.css(
'float': 'right',
'border': '0px',
'background-image': 'url("/default/includes/themes/images/add.png")',
'background-position': 'center center',
'background-repeat': 'no-repeat',
'height': '25px',
'width': '25px',
'cursor': 'pointer',
);
if (recordset.length)
obj.siblings("#btnPlus").click(function ()
var i = obj.children(".recordset").length;
var item = recordset.clone().html();
i++;
item = item.replace(/[([0-9]d0)]/g, "[" + i + "]");
item = item.replace(/_([0-9]d0)_/g, "_" + i + "_");
//$(element).html(item);
//item = $(item).children().first();
//item = $(item).parent();
obj.append(item);
loadMinus(obj.children().last());
minusClick(obj.children().last());
if (options.onAdd != null)
obj.trigger("onAdd", i);
obj.siblings("input[name$='czMore_txtCount']").val(i);
return false;
);
recordset.remove();
for (var j = 0; j <= i; j++)
loadMinus(obj.children()[j]);
minusClick(obj.children()[j]);
if (options.onAdd != null)
obj.trigger("onAdd", j);
if (options.onLoad != null)
obj.trigger("onLoad", i);
//obj.bind("onAdd", function (event, data)
//If you had passed anything in your trigger function, you can grab it using the second parameter in the callback function.
//);
function resetNumbering()
$(obj).children(".recordset").each(function (index, element)
$(element).find('input:text, input:password, input:file, select, textarea').each(function()
old_name = this.name;
new_name = old_name.replace(/_([0-9]d0)_/g, "_" + (index + 1) + "_");
this.id = this.name = new_name;
//alert(this.name);
);
index++
minusClick(element);
);
function loadMinus(recordset)
var divMinus = '<div id="btnMinus" class="btnMinus" />';
$(recordset).children().first().before(divMinus);
var btnMinus = $(recordset).children("#btnMinus");
if(!options.styleOverride)
btnMinus.css(
'float': 'right',
'border': '0px',
'background-image': 'url("/default/includes/themes/images/remove.png")',
'background-position': 'center center',
'background-repeat': 'no-repeat',
'height': '25px',
'width': '25px',
'cursor': 'poitnter',
);
function minusClick(recordset)
$(recordset).children("#btnMinus").click(function ()
var i = obj.children(".recordset").length;
var id = $(recordset).attr("data-id")
$(recordset).remove();
resetNumbering();
obj.siblings("input[name$='czMore_txtCount']").val(obj.children(".recordset").length);
i--;
if (options.onDelete != null)
if (id != null)
obj.trigger("onDelete", id);
);
);
;
)(jQuery);
the above is the jquery code we found on the sourceforge website and tried this code, we have been using this function in other instances so trying to modify its behavior, looks like it do support dynamic naming but somehow it is not working
javascript jquery
I am using the Following Plugin, but every time i create a new fom field, it does not increment the field name, how can i fix this plugin, can't change because we are way ahead with it
/*
Title: Cozeit More plugin by Yasir Atabani
Documentation: na
Author: Yasir O. Atabani
Website: http://www.cozeit.com
Twitter: @yatabani
MIT License, https://github.com/cozeit/czMore/blob/master/LICENSE.md
*/
(function ($, undefined)
$.fn.czMore = function (options)
//Set defauls for the control
var defaults =
max: 5,
min: 0,
onLoad: null,
onAdd: null,
onDelete: null,
styleOverride: false,
;
//Update unset options with defaults if needed
var options = $.extend(defaults, options);
$(this).bind("onAdd", function (event, data)
options.onAdd.call(event, data);
);
$(this).bind("onLoad", function (event, data)
options.onLoad.call(event, data);
);
$(this).bind("onDelete", function (event, data)
options.onDelete.call(event, data);
);
//Executing functionality on all selected elements
return this.each(function ()
var obj = $(this);
var i = obj.children(".recordset").length;
var divPlus = '<div id="btnPlus" class="btnPlus"/>';
var count = '<input id="' + this.id + '_czMore_txtCount" name="' + this.id + '_czMore_txtCount" type="hidden" value="0" size="5" />';
obj.before(count);
var recordset = obj.children("#first");
obj.after(divPlus);
var set = recordset.children(".recordset").children().first();
var btnPlus = obj.siblings("#btnPlus");
if(!options.styleOverride)
btnPlus.css(
'float': 'right',
'border': '0px',
'background-image': 'url("/default/includes/themes/images/add.png")',
'background-position': 'center center',
'background-repeat': 'no-repeat',
'height': '25px',
'width': '25px',
'cursor': 'pointer',
);
if (recordset.length)
obj.siblings("#btnPlus").click(function ()
var i = obj.children(".recordset").length;
var item = recordset.clone().html();
i++;
item = item.replace(/[([0-9]d0)]/g, "[" + i + "]");
item = item.replace(/_([0-9]d0)_/g, "_" + i + "_");
//$(element).html(item);
//item = $(item).children().first();
//item = $(item).parent();
obj.append(item);
loadMinus(obj.children().last());
minusClick(obj.children().last());
if (options.onAdd != null)
obj.trigger("onAdd", i);
obj.siblings("input[name$='czMore_txtCount']").val(i);
return false;
);
recordset.remove();
for (var j = 0; j <= i; j++)
loadMinus(obj.children()[j]);
minusClick(obj.children()[j]);
if (options.onAdd != null)
obj.trigger("onAdd", j);
if (options.onLoad != null)
obj.trigger("onLoad", i);
//obj.bind("onAdd", function (event, data)
//If you had passed anything in your trigger function, you can grab it using the second parameter in the callback function.
//);
function resetNumbering()
$(obj).children(".recordset").each(function (index, element)
$(element).find('input:text, input:password, input:file, select, textarea').each(function()
old_name = this.name;
new_name = old_name.replace(/_([0-9]d0)_/g, "_" + (index + 1) + "_");
this.id = this.name = new_name;
//alert(this.name);
);
index++
minusClick(element);
);
function loadMinus(recordset)
var divMinus = '<div id="btnMinus" class="btnMinus" />';
$(recordset).children().first().before(divMinus);
var btnMinus = $(recordset).children("#btnMinus");
if(!options.styleOverride)
btnMinus.css(
'float': 'right',
'border': '0px',
'background-image': 'url("/default/includes/themes/images/remove.png")',
'background-position': 'center center',
'background-repeat': 'no-repeat',
'height': '25px',
'width': '25px',
'cursor': 'poitnter',
);
function minusClick(recordset)
$(recordset).children("#btnMinus").click(function ()
var i = obj.children(".recordset").length;
var id = $(recordset).attr("data-id")
$(recordset).remove();
resetNumbering();
obj.siblings("input[name$='czMore_txtCount']").val(obj.children(".recordset").length);
i--;
if (options.onDelete != null)
if (id != null)
obj.trigger("onDelete", id);
);
);
;
)(jQuery);
the above is the jquery code we found on the sourceforge website and tried this code, we have been using this function in other instances so trying to modify its behavior, looks like it do support dynamic naming but somehow it is not working
javascript jquery
javascript jquery
asked Nov 13 '18 at 21:41
Smith JonasSmith Jonas
61
61
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289937%2fmodify-the-plugin-to-use-dynamic-naming-for-the-form-fields-added%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289937%2fmodify-the-plugin-to-use-dynamic-naming-for-the-form-fields-added%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown