Created
November 18, 2017 08:44
-
-
Save mdmunir/7897e5c8eeed280fc1cb36b904763fcc to your computer and use it in GitHub Desktop.
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
function prependRow($e) { | |
var settings = $e.data('mdmTabularInput').settings; | |
var counter = settings.counter++; | |
var template = replace(settings.template, settings.replaces, counter); | |
var $row = $(template); | |
var $element = settings.container ? $e.find(settings.container) : $e; | |
var event = $.Event('beforeAdd'); | |
$e.trigger(event, [$row]); | |
if (event.result !== false) { | |
$element.prepend($row); | |
$e.trigger('afterAdd', [$row]); | |
// add js | |
if (settings.templateJs) { | |
var js = replace(settings.templateJs, settings.replaces, counter); | |
eval(js); | |
} | |
// validation for active form | |
if (settings.formSelector && settings.validations && settings.validations.length) { | |
var $form = $(settings.formSelector); | |
var validations = $.extend(true, {}, settings.validations); | |
$.each(validations, function () { | |
var validation = this; | |
$.each(['id', 'name', 'container', 'input'], function () { | |
validation[this] = replace(validation[this], settings.replaces, counter); | |
}); | |
$form.yiiActiveForm('add', validation); | |
}); | |
} | |
$e.mdmTabularInput('rearrage'); | |
} | |
return $row; | |
} | |
$('button').click(function () { | |
prependRow($('#detail-grid')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment