Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update yii2-dynamic-form.js #312

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions src/assets/yii2-dynamic-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,17 @@

// remove "error/success" css class
var yiiActiveFormData = $('#' + widgetOptions.formId).yiiActiveForm('data');
$template.find('.' + yiiActiveFormData.settings.errorCssClass).removeClass(yiiActiveFormData.settings.errorCssClass);
$template.find('.' + yiiActiveFormData.settings.successCssClass).removeClass(yiiActiveFormData.settings.successCssClass);
// $template.find('.' + yiiActiveFormData.settings.errorCssClass).removeClass(yiiActiveFormData.settings.errorCssClass);
// $template.find('.' + yiiActiveFormData.settings.successCssClass).removeClass(yiiActiveFormData.settings.successCssClass);
var $errorCssClass = "has-error"; var $successCssClass = "has-success"; // init default yii class

// seek settings data only if object is not undefined.
if ( typeof yiiActiveFormData != 'undefined') {
$errorCssClass = yiiActiveFormData.settings.errorCssClass;
$successCssClass = yiiActiveFormData.settings.successCssClass;
}
$template.find('.' + $errorCssClass).removeClass($errorCssClass);
$template.find('.' + $successCssClass).removeClass($successCssClass);

return $template;
};
Expand Down Expand Up @@ -208,7 +217,9 @@

widgetsOptions = widgetsOptions.reverse();
for (var i = identifiers.length - 1; i >= 1; i--) {
identifiers[i] = $elem.closest(widgetsOptions[i].widgetItem).index();
if(typeof widgetsOptions[i] !== 'undefined'){
identifiers[i] = $elem.closest(widgetsOptions[i].widgetItem).index();
}
}
}

Expand Down Expand Up @@ -250,7 +261,9 @@

widgetsOptions = widgetsOptions.reverse();
for (var i = identifiers.length - 1; i >= 1; i--) {
identifiers[i] = $elem.closest(widgetsOptions[i].widgetItem).index();
if(typeof widgetsOptions[i] !== 'undefined'){
identifiers[i] = $elem.closest(widgetsOptions[i].widgetItem).index();
}
}
}

Expand Down Expand Up @@ -455,12 +468,12 @@
_restoreKrajeeDepdrop($(this));
}

$.when($('#' + id).select2(configSelect2)).done(initSelect2Loading(id, '.select2-container--krajee'));
$.when($('#' + id).select2(configSelect2)).done(initS2Loading(id, '.select2-container--krajee'));

var kvClose = 'kv_close_' + id.replace(/\-/g, '_');

$('#' + id).on('select2:opening', function(ev) {
initSelect2DropStyle(id, kvClose, ev);
initS2Loading(id, kvClose, ev);
});

$('#' + id).on('select2:unselect', function() {
Expand All @@ -473,6 +486,17 @@
}
});
}

// "kartik-v/yii2-numbercontol"
var $hasNumberControl = $(widgetOptionsRoot.widgetItem).find('[data-krajee-numbercontrol]');
if ($hasNumberControl.length > 0) {
$hasNumberControl.each(function() {
var configNumberControl = eval($(this).attr('data-krajee-numbercontrol'));
configNumberControl.displayId = $(this).parent().prev().attr('id');
if ($(this).data('numberControl')) { $(this).numberControl('destroy'); }
$(this).numberControl(configNumberControl);
});
}
};

})(window.jQuery);