diff --git a/CHANGELOG.md b/CHANGELOG.md index d8a6418..be82011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ dev-master ---------- +version 2.0.2 +------------- +**Date:** 25-Fev-2015 +- bug #22: Correct reset attributes (id, name) when we have more than two nested widgets + + version 2.0.1 ------------- **Date:** 23-Fev-2015 diff --git a/assets/yii2-dynamic-form.js b/assets/yii2-dynamic-form.js index b5078c3..b0de02d 100644 --- a/assets/yii2-dynamic-form.js +++ b/assets/yii2-dynamic-form.js @@ -55,8 +55,8 @@ }; var _parseTemplate = function(widgetOptions) { - var $template = $(widgetOptions.template); + var $template = $(widgetOptions.template); $template.find('div[data-dynamicform]').each(function(){ var widgetOptions = eval($(this).attr('data-dynamicform')); if ($(widgetOptions.widgetItem).length > 1) { @@ -69,7 +69,7 @@ $(this).val(''); }); - $template.find('input[type="checkbox"]').each(function() { + $template.find('input[type="checkbox"], input[type="radio"]').each(function() { var inputName = $(this).attr('name'); var $inputHidden = $template.find('input[type="hidden"][name="' + inputName + '"]').first(); if ($inputHidden) { @@ -95,7 +95,7 @@ return $elem.closest('.' + widgetOptions.widgetContainer).find(widgetOptions.widgetItem).length; }; - var _creatIdentifiers = function(level) { + var _createIdentifiers = function(level) { return new Array(level + 2).join('0').split(''); }; @@ -127,7 +127,7 @@ $elem.find('div[data-dynamicform]').each(function() { var currentWidgetOptions = eval($(this).attr('data-dynamicform')); var level = _getLevel($(this)); - var identifiers = _creatIdentifiers(level); + var identifiers = _createIdentifiers(level); var numItems = $(this).find(currentWidgetOptions.widgetItem).length; for (var i = 1; i <= numItems -1; i++) { @@ -144,7 +144,7 @@ var level = _getLevel($elem.closest('.' + widgetOptions.widgetContainer)); var widgetOptionsRoot = _getWidgetOptionsRoot(widgetOptions); - var identifiers = _creatIdentifiers(level); + var identifiers = _createIdentifiers(level); identifiers[0] = $(widgetOptionsRoot.widgetItem).length - 1; identifiers[level] = count - 1; @@ -176,20 +176,28 @@ } }; - var _updateAttrID = function(widgetOptions, $elem, index, level) { - var id = $elem.attr('id'); - var newID = id; + var _updateAttrID = function($elem, index) { + var widgetOptions = eval($elem.closest('div[data-dynamicform]').attr('data-dynamicform')); + var id = $elem.attr('id'); + var newID = id; if (id !== undefined) { var matches = id.match(regexID); - if (matches && matches.length === 4) { matches[2] = matches[2].substring(1, matches[2].length - 1); var identifiers = matches[2].split('-'); identifiers[0] = index; + + if (identifiers.length > 1) { + var widgetsOptions = []; + $elem.parents('div[data-dynamicform]').each(function(i){ + widgetsOptions[i] = eval($(this).attr('data-dynamicform')); + }); - if (level > 0 && identifiers[level] !== undefined) { - identifiers[level] = $elem.closest(widgetOptions.widgetItem).index(); + widgetsOptions = widgetsOptions.reverse(); + for (var i = identifiers.length - 1; i >= 1; i--) { + identifiers[i] = $elem.closest(widgetsOptions[i].widgetItem).index(); + } } newID = matches[1] + '-' + identifiers.join('-') + '-' + matches[3]; @@ -211,7 +219,7 @@ return newID; }; - var _updateAttrName = function(widgetOptions, $elem, index, level) { + var _updateAttrName = function($elem, index) { var name = $elem.attr('name'); if (name !== undefined) { @@ -222,8 +230,16 @@ var identifiers = matches[2].split('-'); identifiers[0] = index; - if (level > 0 && identifiers[level] !== undefined) { - identifiers[level] = $elem.closest(widgetOptions.widgetItem).index(); + if (identifiers.length > 1) { + var widgetsOptions = []; + $elem.parents('div[data-dynamicform]').each(function(i){ + widgetsOptions[i] = eval($(this).attr('data-dynamicform')); + }); + + widgetsOptions = widgetsOptions.reverse(); + for (var i = identifiers.length - 1; i >= 1; i--) { + identifiers[i] = $elem.closest(widgetsOptions[i].widgetItem).index(); + } } name = matches[1] + '[' + identifiers.join('][') + ']' + matches[3]; @@ -239,34 +255,25 @@ $(widgetOptionsRoot.widgetItem).each(function(index) { var $item = $(this); - var level = 0; - var currentWidgetOptions = widgetOptionsRoot; - $(this).find('*').each(function() { - if ($(this).attr('data-dynamicform') !== undefined) { - currentWidgetOptions = eval($(this).attr('data-dynamicform')); - level = _getLevel($(this)); - } - // update "id" attribute - _updateAttrID(currentWidgetOptions, $(this), index, level); + _updateAttrID($(this), index); // update "name" attribute - _updateAttrName(currentWidgetOptions, $(this), index, level); + _updateAttrName($(this), index); }); }); }; - var _fixFormValidatonInput = function(widgetOptions, input, index, id, name) { - var attribute = input.baseConfig; + var _fixFormValidatonInput = function(widgetOptions, attribute, id, name) { if (attribute !== undefined) { - attribute = $.extend(true, {}, attribute); - attribute.id = id; + attribute = $.extend(true, {}, attribute); + attribute.id = id; attribute.container = ".field-" + id; - attribute.input = "#" + id; - attribute.name = input.name.replace("{}", index); - attribute.value = $("#" + id).val(); - attribute.status = 0; + attribute.input = "#" + id; + attribute.name = name; + attribute.value = $("#" + id).val(); + attribute.status = 0; if ($("#" + widgetOptions.formId).yiiActiveForm("find", id) !== "undefined") { $("#" + widgetOptions.formId).yiiActiveForm("remove", id); @@ -276,42 +283,26 @@ } }; - var _fixFormValidatonInputs = function(widgetOptions, level, index, i) { - widgetOptions.fields.forEach(function(input) { - var identifiers = _creatIdentifiers(level); - var yiiActiveFormAttribute = $("#" + widgetOptions.formId).yiiActiveForm("find", input.id.replace("{}", identifiers.join('-'))); - if (yiiActiveFormAttribute !== undefined) { - input.baseConfig = yiiActiveFormAttribute; - identifiers[0] = index; - identifiers[level] = i; - var id = input.id.replace("{}", identifiers.join('-')); - var name = input.name.replace("{}", identifiers.join('][')); - - _fixFormValidatonInput(widgetOptions, input, i, id, name); - } - }); - }; - var _fixFormValidaton = function(widgetOptions) { var widgetOptionsRoot = _getWidgetOptionsRoot(widgetOptions); - $(widgetOptionsRoot.widgetItem).each(function(index) { - var $item = $(this); - var level = 0; - var currentWidgetOptions = widgetOptionsRoot; - _fixFormValidatonInputs(widgetOptionsRoot, level, index, index); - - $(this).find('div[data-dynamicform]').each(function() { - currentWidgetOptions = eval($(this).attr('data-dynamicform')); - level = _getLevel($(this)); - - if (level > 0) { - $(this).find(currentWidgetOptions.widgetItem).each(function(i) { - - _fixFormValidatonInputs(currentWidgetOptions, level, index, i); - }); + $(widgetOptionsRoot.widgetBody).find('input, textarea, select').each(function() { + var id = $(this).attr('id'); + var name = $(this).attr('name'); + + if (id !== undefined && name !== undefined) { + currentWidgetOptions = eval($(this).closest('div[data-dynamicform]').attr('data-dynamicform')); + var matches = id.match(regexID); + + if (matches && matches.length === 4) { + matches[2] = matches[2].substring(1, matches[2].length - 1); + var level = _getLevel($(this)); + var identifiers = _createIdentifiers(level -1); + var baseID = matches[1] + '-' + identifiers.join('-') + '-' + matches[3]; + var attribute = $("#" + currentWidgetOptions.formId).yiiActiveForm("find", baseID); + _fixFormValidatonInput(currentWidgetOptions, attribute, id, name); } - }); + } }); }; diff --git a/assets/yii2-dynamic-form.min.js b/assets/yii2-dynamic-form.min.js index 08775da..20f869c 100644 --- a/assets/yii2-dynamic-form.min.js +++ b/assets/yii2-dynamic-form.min.js @@ -5,4 +5,4 @@ * * @author Wanderson Bragança */ -!function($){var pluginName="yiiDynamicForm",regexID=/^(.+?)([-\d-]{1,})(.+)$/i,regexName=/(^.+?)([\[\d{1,}\]]{1,})(\[.+\]$)/i;$.fn.yiiDynamicForm=function(e){return methods[e]?methods[e].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof e&&e?($.error("Method "+e+" does not exist on jQuery.yiiDynamicForm"),!1):methods.init.apply(this,arguments)};var events={beforeInsert:"beforeInsert",afterInsert:"afterInsert",beforeDelete:"beforeDelete",afterDelete:"afterDelete",limitReached:"limitReached"},methods={init:function(e){return this.each(function(){e.template=_parseTemplate(e)})},addItem:function(e,t,i){_addItem(e,t,i)},deleteItem:function(e,t,i){_deleteItem(e,t,i)},updateContainer:function(){var widgetOptions=eval($(this).attr("data-dynamicform"));_updateAttributes(widgetOptions),_restoreSpecialJs(widgetOptions),_fixFormValidaton(widgetOptions)}},_parseTemplate=function(widgetOptions){var $template=$(widgetOptions.template);return $template.find("div[data-dynamicform]").each(function(){var widgetOptions=eval($(this).attr("data-dynamicform"));if($(widgetOptions.widgetItem).length>1){var item=$(this).find(widgetOptions.widgetItem).first()[0].outerHTML;$(this).find(widgetOptions.widgetBody).html(item)}}),$template.find("input, textarea, select").each(function(){$(this).val("")}),$template.find('input[type="checkbox"]').each(function(){var e=$(this).attr("name"),t=$template.find('input[type="hidden"][name="'+e+'"]').first();t&&($(this).val(1),t.val(0))}),$template},_getWidgetOptionsRoot=function(widgetOptions){return eval($(widgetOptions.widgetBody).parents("div[data-dynamicform]").last().attr("data-dynamicform"))},_getLevel=function(e){var t=e.parents("div[data-dynamicform]").length;return t=0>t?0:t},_count=function(e,t){return e.closest("."+t.widgetContainer).find(t.widgetItem).length},_creatIdentifiers=function(e){return new Array(e+2).join("0").split("")},_addItem=function(e,t,i){var n=_count(i,e);n1){$elem.find("div[data-dynamicform]").each(function(){for(var currentWidgetOptions=eval($(this).attr("data-dynamicform")),level=_getLevel($(this)),identifiers=_creatIdentifiers(level),numItems=$(this).find(currentWidgetOptions.widgetItem).length,i=1;numItems-1>=i;i++){var aux=identifiers;aux[level]=i,currentWidgetOptions.fields.forEach(function(e){var t=e.id.replace("{}",aux.join("-"));"undefined"!==$("#"+currentWidgetOptions.formId).yiiActiveForm("find",t)&&$("#"+currentWidgetOptions.formId).yiiActiveForm("remove",t)})}});var level=_getLevel($elem.closest("."+widgetOptions.widgetContainer)),widgetOptionsRoot=_getWidgetOptionsRoot(widgetOptions),identifiers=_creatIdentifiers(level);identifiers[0]=$(widgetOptionsRoot.widgetItem).length-1,identifiers[level]=count-1,widgetOptions.fields.forEach(function(e){var t=e.id.replace("{}",identifiers.join("-"));"undefined"!==$("#"+widgetOptions.formId).yiiActiveForm("find",t)&&$("#"+widgetOptions.formId).yiiActiveForm("remove",t)})}},_deleteItem=function(e,t,i){var n=_count(i,e);if(n>e.min){$todelete=i.closest(e.widgetItem);var a=$("."+e.widgetContainer).triggerHandler(events.beforeDelete,$todelete);a!==!1&&(_removeValidations($todelete,e,n),$todelete.remove(),_updateAttributes(e),_restoreSpecialJs(e),_fixFormValidaton(e),$("."+e.widgetContainer).triggerHandler(events.afterDelete))}},_updateAttrID=function(e,t,i,n){var a=t.attr("id"),o=a;if(void 0!==a){var d=a.match(regexID);if(d&&4===d.length){d[2]=d[2].substring(1,d[2].length-1);var r=d[2].split("-");r[0]=i,n>0&&void 0!==r[n]&&(r[n]=t.closest(e.widgetItem).index()),o=d[1]+"-"+r.join("-")+"-"+d[3],t.attr("id",o)}else o=a+i,t.attr("id",o)}return a!==o&&(t.closest(e.widgetItem).find(".field-"+a).each(function(){$(this).removeClass("field-"+a).addClass("field-"+o)}),t.closest(e.widgetItem).find("label[for='"+a+"']").attr("for",o)),o},_updateAttrName=function(e,t,i,n){var a=t.attr("name");if(void 0!==a){var o=a.match(regexName);if(o&&4===o.length){o[2]=o[2].replace(/\]\[/g,"-").replace(/\]|\[/g,"");var d=o[2].split("-");d[0]=i,n>0&&void 0!==d[n]&&(d[n]=t.closest(e.widgetItem).index()),a=o[1]+"["+d.join("][")+"]"+o[3],t.attr("name",a)}}return a},_updateAttributes=function(widgetOptions){var widgetOptionsRoot=_getWidgetOptionsRoot(widgetOptions);$(widgetOptionsRoot.widgetItem).each(function(index){var $item=$(this),level=0,currentWidgetOptions=widgetOptionsRoot;$(this).find("*").each(function(){void 0!==$(this).attr("data-dynamicform")&&(currentWidgetOptions=eval($(this).attr("data-dynamicform")),level=_getLevel($(this))),_updateAttrID(currentWidgetOptions,$(this),index,level),_updateAttrName(currentWidgetOptions,$(this),index,level)})})},_fixFormValidatonInput=function(e,t,i,n){var a=t.baseConfig;void 0!==a&&(a=$.extend(!0,{},a),a.id=n,a.container=".field-"+n,a.input="#"+n,a.name=t.name.replace("{}",i),a.value=$("#"+n).val(),a.status=0,"undefined"!==$("#"+e.formId).yiiActiveForm("find",n)&&$("#"+e.formId).yiiActiveForm("remove",n),$("#"+e.formId).yiiActiveForm("add",a))},_fixFormValidatonInputs=function(e,t,i,n){e.fields.forEach(function(a){var o=_creatIdentifiers(t),d=$("#"+e.formId).yiiActiveForm("find",a.id.replace("{}",o.join("-")));if(void 0!==d){a.baseConfig=d,o[0]=i,o[t]=n;var r=a.id.replace("{}",o.join("-")),s=a.name.replace("{}",o.join("]["));_fixFormValidatonInput(e,a,n,r,s)}})},_fixFormValidaton=function(widgetOptions){var widgetOptionsRoot=_getWidgetOptionsRoot(widgetOptions);$(widgetOptionsRoot.widgetItem).each(function(index){var $item=$(this),level=0,currentWidgetOptions=widgetOptionsRoot;_fixFormValidatonInputs(widgetOptionsRoot,level,index,index),$(this).find("div[data-dynamicform]").each(function(){currentWidgetOptions=eval($(this).attr("data-dynamicform")),level=_getLevel($(this)),level>0&&$(this).find(currentWidgetOptions.widgetItem).each(function(e){_fixFormValidatonInputs(currentWidgetOptions,level,index,e)})})})},_restoreSpecialJs=function(widgetOptions){var widgetOptionsRoot=_getWidgetOptionsRoot(widgetOptions),$hasDatepicker=$(widgetOptionsRoot.widgetItem).find("[data-krajee-datepicker]");$hasDatepicker.length>0&&$hasDatepicker.each(function(){$(this).parent().removeData().datepicker("remove"),$(this).parent().datepicker(eval($(this).attr("data-krajee-datepicker")))});var $hasTimepicker=$(widgetOptionsRoot.widgetItem).find("[data-krajee-timepicker]");$hasTimepicker.length>0&&$hasTimepicker.each(function(){$(this).removeData().off(),$(this).parent().find(".bootstrap-timepicker-widget").remove(),$(this).unbind(),$(this).timepicker(eval($(this).attr("data-krajee-timepicker")))});var $hasMaskmoney=$(widgetOptionsRoot.widgetItem).find("[data-krajee-maskMoney]");$hasMaskmoney.length>0&&$hasMaskmoney.each(function(){$(this).parent().find("input").removeData().off();var id="#"+$(this).attr("id"),displayID=id+"-disp";$(displayID).maskMoney("destroy"),$(displayID).maskMoney(eval($(this).attr("data-krajee-maskMoney"))),$(displayID).maskMoney("mask",parseFloat($(id).val())),$(displayID).on("change",function(){var e=$(displayID).maskMoney("unmasked")[0];$(id).val(e),$(id).trigger("change")})});var $hasFileinput=$(widgetOptionsRoot.widgetItem).find("[data-krajee-fileinput]");$hasFileinput.length>0&&$hasFileinput.each(function(){$(this).fileinput(eval($(this).attr("data-krajee-fileinput")))});var $hasTouchSpin=$(widgetOptionsRoot.widgetItem).find("[data-krajee-TouchSpin]");$hasTouchSpin.length>0&&$hasTouchSpin.each(function(){$(this).TouchSpin("destroy"),$(this).TouchSpin(eval($(this).attr("data-krajee-TouchSpin")))});var $hasSpectrum=$(widgetOptionsRoot.widgetItem).find("[data-krajee-spectrum]");$hasSpectrum.length>0&&$hasSpectrum.each(function(){var id="#"+$(this).attr("id"),sourceID=id+"-source";$(sourceID).spectrum("destroy"),$(sourceID).unbind(),$(id).unbind();var configSpectrum=eval($(this).attr("data-krajee-spectrum"));configSpectrum.change=function(e){jQuery(id).val(e.toString())},$(sourceID).attr("name",$(sourceID).attr("id")),$(sourceID).spectrum(configSpectrum),$(sourceID).spectrum("set",jQuery(id).val()),$(id).on("change",function(){$(sourceID).spectrum("set",jQuery(id).val())})});var $hasDepdrop=$(widgetOptionsRoot.widgetItem).find("[data-krajee-depdrop]");$hasDepdrop.length>0&&$hasDepdrop.each(function(){$(this).removeData().off(),$(this).unbind();var configDepdrop=eval($(this).attr("data-krajee-depdrop")),inputID=$(this).attr("id"),matchID=inputID.match(regex);if(matchID&&4===matchID.length)for(index=0;index0&&$hasSelect2.each(function(){var id=$(this).attr("id"),configSelect2=eval($(this).attr("data-krajee-select2"));$(this).select2("destroy"),$.when($("#"+id).select2(configSelect2)).done(initSelect2Loading(id)),$("#"+id).on("select2-open",function(){initSelect2DropStyle(id)}),$(this).attr("data-krajee-depdrop")&&($(this).on("depdrop.beforeChange",function(e,i,v){var configDepdrop=eval($(this).attr("data-krajee-depdrop")),loadingText=configDepdrop.loadingText?configDepdrop.loadingText:"Loading ...";$("#"+id).select2("data",{text:loadingText})}),$(this).on("depdrop.change",function(){$("#"+id).select2("val",$("#"+id).val())}))})}}(window.jQuery); +!function($){var pluginName="yiiDynamicForm",regexID=/^(.+?)([-\d-]{1,})(.+)$/i,regexName=/(^.+?)([\[\d{1,}\]]{1,})(\[.+\]$)/i;$.fn.yiiDynamicForm=function(e){return methods[e]?methods[e].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof e&&e?($.error("Method "+e+" does not exist on jQuery.yiiDynamicForm"),!1):methods.init.apply(this,arguments)};var events={beforeInsert:"beforeInsert",afterInsert:"afterInsert",beforeDelete:"beforeDelete",afterDelete:"afterDelete",limitReached:"limitReached"},methods={init:function(e){return this.each(function(){e.template=_parseTemplate(e)})},addItem:function(e,t,i){_addItem(e,t,i)},deleteItem:function(e,t,i){_deleteItem(e,t,i)},updateContainer:function(){var widgetOptions=eval($(this).attr("data-dynamicform"));_updateAttributes(widgetOptions),_restoreSpecialJs(widgetOptions),_fixFormValidaton(widgetOptions)}},_parseTemplate=function(widgetOptions){var $template=$(widgetOptions.template);return $template.find("div[data-dynamicform]").each(function(){var widgetOptions=eval($(this).attr("data-dynamicform"));if($(widgetOptions.widgetItem).length>1){var item=$(this).find(widgetOptions.widgetItem).first()[0].outerHTML;$(this).find(widgetOptions.widgetBody).html(item)}}),$template.find("input, textarea, select").each(function(){$(this).val("")}),$template.find('input[type="checkbox"], input[type="radio"]').each(function(){var e=$(this).attr("name"),t=$template.find('input[type="hidden"][name="'+e+'"]').first();t&&($(this).val(1),t.val(0))}),$template},_getWidgetOptionsRoot=function(widgetOptions){return eval($(widgetOptions.widgetBody).parents("div[data-dynamicform]").last().attr("data-dynamicform"))},_getLevel=function(e){var t=e.parents("div[data-dynamicform]").length;return t=0>t?0:t},_count=function(e,t){return e.closest("."+t.widgetContainer).find(t.widgetItem).length},_createIdentifiers=function(e){return new Array(e+2).join("0").split("")},_addItem=function(e,t,i){var n=_count(i,e);n1){$elem.find("div[data-dynamicform]").each(function(){for(var currentWidgetOptions=eval($(this).attr("data-dynamicform")),level=_getLevel($(this)),identifiers=_createIdentifiers(level),numItems=$(this).find(currentWidgetOptions.widgetItem).length,i=1;numItems-1>=i;i++){var aux=identifiers;aux[level]=i,currentWidgetOptions.fields.forEach(function(e){var t=e.id.replace("{}",aux.join("-"));"undefined"!==$("#"+currentWidgetOptions.formId).yiiActiveForm("find",t)&&$("#"+currentWidgetOptions.formId).yiiActiveForm("remove",t)})}});var level=_getLevel($elem.closest("."+widgetOptions.widgetContainer)),widgetOptionsRoot=_getWidgetOptionsRoot(widgetOptions),identifiers=_createIdentifiers(level);identifiers[0]=$(widgetOptionsRoot.widgetItem).length-1,identifiers[level]=count-1,widgetOptions.fields.forEach(function(e){var t=e.id.replace("{}",identifiers.join("-"));"undefined"!==$("#"+widgetOptions.formId).yiiActiveForm("find",t)&&$("#"+widgetOptions.formId).yiiActiveForm("remove",t)})}},_deleteItem=function(e,t,i){var n=_count(i,e);if(n>e.min){$todelete=i.closest(e.widgetItem);var a=$("."+e.widgetContainer).triggerHandler(events.beforeDelete,$todelete);a!==!1&&(_removeValidations($todelete,e,n),$todelete.remove(),_updateAttributes(e),_restoreSpecialJs(e),_fixFormValidaton(e),$("."+e.widgetContainer).triggerHandler(events.afterDelete))}},_updateAttrID=function($elem,index){var widgetOptions=eval($elem.closest("div[data-dynamicform]").attr("data-dynamicform")),id=$elem.attr("id"),newID=id;if(void 0!==id){var matches=id.match(regexID);if(matches&&4===matches.length){matches[2]=matches[2].substring(1,matches[2].length-1);var identifiers=matches[2].split("-");if(identifiers[0]=index,identifiers.length>1){var widgetsOptions=[];$elem.parents("div[data-dynamicform]").each(function(i){widgetsOptions[i]=eval($(this).attr("data-dynamicform"))}),widgetsOptions=widgetsOptions.reverse();for(var i=identifiers.length-1;i>=1;i--)identifiers[i]=$elem.closest(widgetsOptions[i].widgetItem).index()}newID=matches[1]+"-"+identifiers.join("-")+"-"+matches[3],$elem.attr("id",newID)}else newID=id+index,$elem.attr("id",newID)}return id!==newID&&($elem.closest(widgetOptions.widgetItem).find(".field-"+id).each(function(){$(this).removeClass("field-"+id).addClass("field-"+newID)}),$elem.closest(widgetOptions.widgetItem).find("label[for='"+id+"']").attr("for",newID)),newID},_updateAttrName=function($elem,index){var name=$elem.attr("name");if(void 0!==name){var matches=name.match(regexName);if(matches&&4===matches.length){matches[2]=matches[2].replace(/\]\[/g,"-").replace(/\]|\[/g,"");var identifiers=matches[2].split("-");if(identifiers[0]=index,identifiers.length>1){var widgetsOptions=[];$elem.parents("div[data-dynamicform]").each(function(i){widgetsOptions[i]=eval($(this).attr("data-dynamicform"))}),widgetsOptions=widgetsOptions.reverse();for(var i=identifiers.length-1;i>=1;i--)identifiers[i]=$elem.closest(widgetsOptions[i].widgetItem).index()}name=matches[1]+"["+identifiers.join("][")+"]"+matches[3],$elem.attr("name",name)}}return name},_updateAttributes=function(e){var t=_getWidgetOptionsRoot(e);$(t.widgetItem).each(function(e){$(this);$(this).find("*").each(function(){_updateAttrID($(this),e),_updateAttrName($(this),e)})})},_fixFormValidatonInput=function(e,t,i,n){void 0!==t&&(t=$.extend(!0,{},t),t.id=i,t.container=".field-"+i,t.input="#"+i,t.name=n,t.value=$("#"+i).val(),t.status=0,"undefined"!==$("#"+e.formId).yiiActiveForm("find",i)&&$("#"+e.formId).yiiActiveForm("remove",i),$("#"+e.formId).yiiActiveForm("add",t))},_fixFormValidaton=function(widgetOptions){var widgetOptionsRoot=_getWidgetOptionsRoot(widgetOptions);$(widgetOptionsRoot.widgetBody).find("input, textarea, select").each(function(){var id=$(this).attr("id"),name=$(this).attr("name");if(void 0!==id&&void 0!==name){currentWidgetOptions=eval($(this).closest("div[data-dynamicform]").attr("data-dynamicform"));var matches=id.match(regexID);if(matches&&4===matches.length){matches[2]=matches[2].substring(1,matches[2].length-1);var level=_getLevel($(this)),identifiers=_createIdentifiers(level-1),baseID=matches[1]+"-"+identifiers.join("-")+"-"+matches[3],attribute=$("#"+currentWidgetOptions.formId).yiiActiveForm("find",baseID);_fixFormValidatonInput(currentWidgetOptions,attribute,id,name)}}})},_restoreSpecialJs=function(widgetOptions){var widgetOptionsRoot=_getWidgetOptionsRoot(widgetOptions),$hasDatepicker=$(widgetOptionsRoot.widgetItem).find("[data-krajee-datepicker]");$hasDatepicker.length>0&&$hasDatepicker.each(function(){$(this).parent().removeData().datepicker("remove"),$(this).parent().datepicker(eval($(this).attr("data-krajee-datepicker")))});var $hasTimepicker=$(widgetOptionsRoot.widgetItem).find("[data-krajee-timepicker]");$hasTimepicker.length>0&&$hasTimepicker.each(function(){$(this).removeData().off(),$(this).parent().find(".bootstrap-timepicker-widget").remove(),$(this).unbind(),$(this).timepicker(eval($(this).attr("data-krajee-timepicker")))});var $hasMaskmoney=$(widgetOptionsRoot.widgetItem).find("[data-krajee-maskMoney]");$hasMaskmoney.length>0&&$hasMaskmoney.each(function(){$(this).parent().find("input").removeData().off();var id="#"+$(this).attr("id"),displayID=id+"-disp";$(displayID).maskMoney("destroy"),$(displayID).maskMoney(eval($(this).attr("data-krajee-maskMoney"))),$(displayID).maskMoney("mask",parseFloat($(id).val())),$(displayID).on("change",function(){var e=$(displayID).maskMoney("unmasked")[0];$(id).val(e),$(id).trigger("change")})});var $hasFileinput=$(widgetOptionsRoot.widgetItem).find("[data-krajee-fileinput]");$hasFileinput.length>0&&$hasFileinput.each(function(){$(this).fileinput(eval($(this).attr("data-krajee-fileinput")))});var $hasTouchSpin=$(widgetOptionsRoot.widgetItem).find("[data-krajee-TouchSpin]");$hasTouchSpin.length>0&&$hasTouchSpin.each(function(){$(this).TouchSpin("destroy"),$(this).TouchSpin(eval($(this).attr("data-krajee-TouchSpin")))});var $hasSpectrum=$(widgetOptionsRoot.widgetItem).find("[data-krajee-spectrum]");$hasSpectrum.length>0&&$hasSpectrum.each(function(){var id="#"+$(this).attr("id"),sourceID=id+"-source";$(sourceID).spectrum("destroy"),$(sourceID).unbind(),$(id).unbind();var configSpectrum=eval($(this).attr("data-krajee-spectrum"));configSpectrum.change=function(e){jQuery(id).val(e.toString())},$(sourceID).attr("name",$(sourceID).attr("id")),$(sourceID).spectrum(configSpectrum),$(sourceID).spectrum("set",jQuery(id).val()),$(id).on("change",function(){$(sourceID).spectrum("set",jQuery(id).val())})});var $hasDepdrop=$(widgetOptionsRoot.widgetItem).find("[data-krajee-depdrop]");$hasDepdrop.length>0&&$hasDepdrop.each(function(){$(this).removeData().off(),$(this).unbind();var configDepdrop=eval($(this).attr("data-krajee-depdrop")),inputID=$(this).attr("id"),matchID=inputID.match(regex);if(matchID&&4===matchID.length)for(index=0;index0&&$hasSelect2.each(function(){var id=$(this).attr("id"),configSelect2=eval($(this).attr("data-krajee-select2"));$(this).select2("destroy"),$.when($("#"+id).select2(configSelect2)).done(initSelect2Loading(id)),$("#"+id).on("select2-open",function(){initSelect2DropStyle(id)}),$(this).attr("data-krajee-depdrop")&&($(this).on("depdrop.beforeChange",function(e,i,v){var configDepdrop=eval($(this).attr("data-krajee-depdrop")),loadingText=configDepdrop.loadingText?configDepdrop.loadingText:"Loading ...";$("#"+id).select2("data",{text:loadingText})}),$(this).on("depdrop.change",function(){$("#"+id).select2("val",$("#"+id).val())}))})}}(window.jQuery);