"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "framework/assets/yii.activeForm.js" between
yii2-2.0.36.tar.gz and yii2-2.0.37.tar.gz

About: Yii 2 is a high-performance component-based PHP framework for developing large-scale Web applications (source).

yii.activeForm.js  (yii2-2.0.36):yii.activeForm.js  (yii2-2.0.37)
skipping to change at line 17 skipping to change at line 17
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
(function ($) { (function ($) {
$.fn.yiiActiveForm = function (method) { $.fn.yiiActiveForm = function (method) {
if (methods[method]) { if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(argume nts, 1)); return methods[method].apply(this, Array.prototype.slice.call(argume nts, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else { } else {
$.error('Method ' + method + ' does not exist on jQuery.yiiActiveFor if (typeof method === 'object' || !method) {
m'); return methods.init.apply(this, arguments);
return false; } else {
$.error('Method ' + method + ' does not exist on jQuery.yiiActiv
eForm');
return false;
}
} }
}; };
var events = { var events = {
/** /**
* beforeValidate event is triggered before validating the whole form. * beforeValidate event is triggered before validating the whole form.
* The signature of the event handler should be: * The signature of the event handler should be:
* function (event, messages, deferreds) * function (event, messages, deferreds)
* where * where
* - event: an Event object. * - event: an Event object.
skipping to change at line 180 skipping to change at line 182
// whether the validation is cancelled by beforeValidateAttribute event handler // whether the validation is cancelled by beforeValidateAttribute event handler
cancelled: false, cancelled: false,
// the value of the input // the value of the input
value: undefined, value: undefined,
// whether to update aria-invalid attribute after validation // whether to update aria-invalid attribute after validation
updateAriaInvalid: true updateAriaInvalid: true
}; };
var submitDefer; var submitDefer;
var setSubmitFinalizeDefer = function($form) { var setSubmitFinalizeDefer = function ($form) {
submitDefer = $.Deferred(); submitDefer = $.Deferred();
$form.data('yiiSubmitFinalizePromise', submitDefer.promise()); $form.data('yiiSubmitFinalizePromise', submitDefer.promise());
}; };
// finalize yii.js $form.submit // finalize yii.js $form.submit
var submitFinalize = function($form) { var submitFinalize = function ($form) {
if(submitDefer) { if (submitDefer) {
submitDefer.resolve(); submitDefer.resolve();
submitDefer = undefined; submitDefer = undefined;
$form.removeData('yiiSubmitFinalizePromise'); $form.removeData('yiiSubmitFinalizePromise');
} }
}; };
var methods = { var methods = {
init: function (attributes, options) { init: function (attributes, options) {
return this.each(function () { return this.each(function () {
var $form = $(this); var $form = $(this);
skipping to change at line 328 skipping to change at line 330
submitFinalize($form); submitFinalize($form);
return; return;
} }
} }
// client-side validation // client-side validation
$.each(data.attributes, function () { $.each(data.attributes, function () {
this.$form = $form; this.$form = $form;
var $input = findInput($form, this); var $input = findInput($form, this);
if ($input.is(":disabled")) { if ($input.is(':disabled')) {
return true; return true;
} }
// pass SELECT without options // validate markup for select input
if ($input.length && $input[0].tagName.toLowerCase() === 'select ') { if ($input.length && $input[0].tagName.toLowerCase() === 'select ') {
if (!$input[0].options.length) { var opts = $input[0].options, isEmpty = !opts || !opts.lengt
return true; h, isRequired = $input.attr('required'),
} else if (($input[0].options.length === 1) && ($input[0].op isMultiple = $input.attr('multiple'), size = $input.attr
tions[0].value === '')) { ('size') || 1;
return true; // check if valid HTML markup for select input, else return
validation as `true`
// https://w3c.github.io/html-reference/select.html
if (isRequired && !isMultiple && parseInt(size, 10) === 1) {
// invalid select markup condition
if (isEmpty) { // empty option elements for the select
return true;
}
if (opts[0] && (opts[0].value !== '' && opts[0].text !==
'')) { // first option is not empty
return true;
}
} }
} }
this.cancelled = false; this.cancelled = false;
// perform validation only if the form is being submitted or if an attribute is pending validation // perform validation only if the form is being submitted or if an attribute is pending validation
if (data.submitting || this.status === 2 || this.status === 3) { if (data.submitting || this.status === 2 || this.status === 3) {
var msg = messages[this.id]; var msg = messages[this.id];
if (msg === undefined) { if (msg === undefined) {
msg = []; msg = [];
messages[this.id] = msg; messages[this.id] = msg;
} }
skipping to change at line 364 skipping to change at line 373
if (this.enableAjaxValidation) { if (this.enableAjaxValidation) {
needAjaxValidation = true; needAjaxValidation = true;
} }
} else { } else {
this.cancelled = true; this.cancelled = true;
} }
} }
}); });
// ajax validation // ajax validation
$.when.apply(this, deferreds).always(function() { $.when.apply(this, deferreds).always(function () {
// Remove empty message arrays // Remove empty message arrays
for (var i in messages) { for (var i in messages) {
if (0 === messages[i].length) { if (0 === messages[i].length) {
delete messages[i]; delete messages[i];
} }
} }
if (needAjaxValidation && ($.isEmptyObject(messages) || data.sub mitting)) { if (needAjaxValidation && ($.isEmptyObject(messages) || data.sub mitting)) {
var $button = data.submitObject, var $button = data.submitObject,
extData = '&' + data.settings.ajaxParam + '=' + $form.at tr('id'); extData = '&' + data.settings.ajaxParam + '=' + $form.at tr('id');
if ($button && $button.length && $button.attr('name')) { if ($button && $button.length && $button.attr('name')) {
skipping to change at line 405 skipping to change at line 414
updateInputs($form, $.extend(messages, msgs), su bmitting); updateInputs($form, $.extend(messages, msgs), su bmitting);
} else { } else {
updateInputs($form, messages, submitting); updateInputs($form, messages, submitting);
} }
}, },
error: function () { error: function () {
data.submitting = false; data.submitting = false;
submitFinalize($form); submitFinalize($form);
} }
}); });
} else if (data.submitting) {
// delay callback so that the form can be submitted without
problem
window.setTimeout(function () {
updateInputs($form, messages, submitting);
}, 200);
} else { } else {
updateInputs($form, messages, submitting); if (data.submitting) {
// delay callback so that the form can be submitted with
out problem
window.setTimeout(function () {
updateInputs($form, messages, submitting);
}, 200);
} else {
updateInputs($form, messages, submitting);
}
} }
}); });
}, },
submitForm: function () { submitForm: function () {
var $form = $(this), var $form = $(this),
data = $form.data('yiiActiveForm'); data = $form.data('yiiActiveForm');
if (data.validated) { if (data.validated) {
// Second submit's call (from validate/updateInputs) // Second submit's call (from validate/updateInputs)
data.submitting = false; data.submitting = false;
skipping to change at line 460 skipping to change at line 471
window.setTimeout(function () { window.setTimeout(function () {
$.each(data.attributes, function () { $.each(data.attributes, function () {
// Without setTimeout() we would get the input values that a re not reset yet. // Without setTimeout() we would get the input values that a re not reset yet.
this.value = getValue($form, this); this.value = getValue($form, this);
this.status = 0; this.status = 0;
var $container = $form.find(this.container), var $container = $form.find(this.container),
$input = findInput($form, this), $input = findInput($form, this),
$errorElement = data.settings.validationStateOn === 'inp ut' ? $input : $container; $errorElement = data.settings.validationStateOn === 'inp ut' ? $input : $container;
$errorElement.removeClass( $errorElement.removeClass(
data.settings.validatingCssClass + ' ' + data.settings.validatingCssClass + ' ' +
data.settings.errorCssClass + ' ' + data.settings.errorCssClass + ' ' +
data.settings.successCssClass data.settings.successCssClass
); );
$container.find(this.error).html(''); $container.find(this.error).html('');
}); });
$form.find(data.settings.errorSummary).hide().find('ul').html('' ); $form.find(data.settings.errorSummary).hide().find('ul').html('' );
}, 1); }, 1);
}, },
/** /**
* Updates error messages, input containers, and optionally summary as w ell. * Updates error messages, input containers, and optionally summary as w ell.
* If an attribute is missing from messages, it is considered valid. * If an attribute is missing from messages, it is considered valid.
skipping to change at line 493 skipping to change at line 504
updateSummary($form, messages); updateSummary($form, messages);
} }
}, },
/** /**
* Updates error messages and input container of a single attribute. * Updates error messages and input container of a single attribute.
* If messages is empty, the attribute is considered valid. * If messages is empty, the attribute is considered valid.
* @param id attribute ID * @param id attribute ID
* @param messages array with error messages * @param messages array with error messages
*/ */
updateAttribute: function(id, messages) { updateAttribute: function (id, messages) {
var attribute = methods.find.call(this, id); var attribute = methods.find.call(this, id);
if (attribute != undefined) { if (attribute != undefined) {
var msg = {}; var msg = {};
msg[id] = messages; msg[id] = messages;
updateInput($(this), attribute, msg); updateInput($(this), attribute, msg);
} }
} }
}; };
var watchAttribute = function ($form, attribute) { var watchAttribute = function ($form, attribute) {
skipping to change at line 519 skipping to change at line 530
} }
if (attribute.validateOnBlur) { if (attribute.validateOnBlur) {
$input.on('blur.yiiActiveForm', function () { $input.on('blur.yiiActiveForm', function () {
if (attribute.status == 0 || attribute.status == 1) { if (attribute.status == 0 || attribute.status == 1) {
validateAttribute($form, attribute, true); validateAttribute($form, attribute, true);
} }
}); });
} }
if (attribute.validateOnType) { if (attribute.validateOnType) {
$input.on('keyup.yiiActiveForm', function (e) { $input.on('keyup.yiiActiveForm', function (e) {
if ($.inArray(e.which, [16, 17, 18, 37, 38, 39, 40]) !== -1 ) { if ($.inArray(e.which, [16, 17, 18, 37, 38, 39, 40]) !== -1) {
return; return;
} }
if (attribute.value !== getValue($form, attribute)) { if (attribute.value !== getValue($form, attribute)) {
validateAttribute($form, attribute, false, attribute.validat ionDelay); validateAttribute($form, attribute, false, attribute.validat ionDelay);
} }
}); });
} }
}; };
var unwatchAttribute = function ($form, attribute) { var unwatchAttribute = function ($form, attribute) {
skipping to change at line 572 skipping to change at line 583
methods.validate.call($form); methods.validate.call($form);
}, validationDelay ? validationDelay : 200); }, validationDelay ? validationDelay : 200);
}; };
/** /**
* Compares two value whatever it objects, arrays or simple types * Compares two value whatever it objects, arrays or simple types
* @param val1 * @param val1
* @param val2 * @param val2
* @returns boolean * @returns boolean
*/ */
var isEqual = function(val1, val2) { var isEqual = function (val1, val2) {
// objects // objects
if (val1 instanceof Object) { if (val1 instanceof Object) {
return isObjectsEqual(val1, val2) return isObjectsEqual(val1, val2)
} }
// arrays // arrays
if (Array.isArray(val1)) { if (Array.isArray(val1)) {
return isArraysEqual(val1, val2); return isArraysEqual(val1, val2);
} }
// simple types // simple types
return val1 === val2; return val1 === val2;
}; };
/** /**
* Compares two objects * Compares two objects
* @param obj1 * @param obj1
* @param obj2 * @param obj2
* @returns boolean * @returns boolean
*/ */
var isObjectsEqual = function(obj1, obj2) { var isObjectsEqual = function (obj1, obj2) {
if (!(obj1 instanceof Object) || !(obj2 instanceof Object)) { if (!(obj1 instanceof Object) || !(obj2 instanceof Object)) {
return false; return false;
} }
var keys1 = Object.keys(obj1); var keys1 = Object.keys(obj1);
var keys2 = Object.keys(obj2); var keys2 = Object.keys(obj2);
if (keys1.length !== keys2.length) { if (keys1.length !== keys2.length) {
return false; return false;
} }
skipping to change at line 622 skipping to change at line 633
return true; return true;
}; };
/** /**
* Compares two arrays * Compares two arrays
* @param arr1 * @param arr1
* @param arr2 * @param arr2
* @returns boolean * @returns boolean
*/ */
var isArraysEqual = function(arr1, arr2) { var isArraysEqual = function (arr1, arr2) {
if (!Array.isArray(arr1) || !Array.isArray(arr2)) { if (!Array.isArray(arr1) || !Array.isArray(arr2)) {
return false; return false;
} }
if (arr1.length !== arr2.length) { if (arr1.length !== arr2.length) {
return false; return false;
} }
for (var i = 0; i < arr1.length; i += 1) { for (var i = 0; i < arr1.length; i += 1) {
if (arr1[i] !== arr2[i]) { if (arr1[i] !== arr2[i]) {
return false; return false;
skipping to change at line 645 skipping to change at line 656
return true; return true;
}; };
/** /**
* Returns an array prototype with a shortcut method for adding a new deferr ed. * Returns an array prototype with a shortcut method for adding a new deferr ed.
* The context of the callback will be the deferred object so it can be reso lved like ```this.resolve()``` * The context of the callback will be the deferred object so it can be reso lved like ```this.resolve()```
* @returns Array * @returns Array
*/ */
var deferredArray = function () { var deferredArray = function () {
var array = []; var array = [];
array.add = function(callback) { array.add = function (callback) {
this.push(new $.Deferred(callback)); this.push(new $.Deferred(callback));
}; };
return array; return array;
}; };
var buttonOptions = ['action', 'target', 'method', 'enctype']; var buttonOptions = ['action', 'target', 'method', 'enctype'];
/** /**
* Returns current form options * Returns current form options
* @param $form * @param $form
skipping to change at line 708 skipping to change at line 719
*/ */
var updateInputs = function ($form, messages, submitting) { var updateInputs = function ($form, messages, submitting) {
var data = $form.data('yiiActiveForm'); var data = $form.data('yiiActiveForm');
if (data === undefined) { if (data === undefined) {
return false; return false;
} }
var errorAttributes = [], $input; var errorAttributes = [], $input;
$.each(data.attributes, function () { $.each(data.attributes, function () {
var hasError = (submitting && updateInput($form, this, messages)) || var hasError = (submitting && updateInput($form, this, messages)) ||
(!submitting && attrHasError($form, this, messages)); (!submitting && attrHasError($form,
this, messages));
$input = findInput($form, this); $input = findInput($form, this);
if (!$input.is(":disabled") && !this.cancelled && hasError) { if (!$input.is(':disabled') && !this.cancelled && hasError) {
errorAttributes.push(this); errorAttributes.push(this);
} }
}); });
$form.trigger(events.afterValidate, [messages, errorAttributes]); $form.trigger(events.afterValidate, [messages, errorAttributes]);
if (submitting) { if (submitting) {
updateSummary($form, messages); updateSummary($form, messages);
if (errorAttributes.length) { if (errorAttributes.length) {
if (data.settings.scrollToError) { if (data.settings.scrollToError) {
var top = $form.find($.map(errorAttributes, function(attribu te) { var h = $(document).height(), top = $form.find($.map(errorAt tributes, function (attribute) {
return attribute.input; return attribute.input;
}).join(',')).first().closest(':visible').offset().top - dat a.settings.scrollToErrorOffset; }).join(',')).first().closest(':visible').offset().top - dat a.settings.scrollToErrorOffset;
if (top < 0) { top = top < 0 ? 0 : (top > h ? h : top);
top = 0;
} else if (top > $(document).height()) {
top = $(document).height();
}
var wtop = $(window).scrollTop(); var wtop = $(window).scrollTop();
if (top < wtop || top > wtop + $(window).height()) { if (top < wtop || top > wtop + $(window).height()) {
$(window).scrollTop(top); $(window).scrollTop(top);
} }
} }
data.submitting = false; data.submitting = false;
} else { } else {
data.validated = true; data.validated = true;
if (data.submitObject) { if (data.submitObject) {
applyButtonOptions($form, data.submitObject); applyButtonOptions($form, data.submitObject);
skipping to change at line 810 skipping to change at line 818
var $errorElement = data.settings.validationStateOn === 'input' ? $i nput : $container; var $errorElement = data.settings.validationStateOn === 'input' ? $i nput : $container;
if (hasError) { if (hasError) {
if (attribute.encodeError) { if (attribute.encodeError) {
$error.text(messages[attribute.id][0]); $error.text(messages[attribute.id][0]);
} else { } else {
$error.html(messages[attribute.id][0]); $error.html(messages[attribute.id][0]);
} }
$errorElement.removeClass(data.settings.validatingCssClass + ' ' + data.settings.successCssClass) $errorElement.removeClass(data.settings.validatingCssClass + ' ' + data.settings.successCssClass)
.addClass(data.settings.errorCssClass); .addClass(data.settings.errorCssClass);
} else { } else {
$error.empty(); $error.empty();
$errorElement.removeClass(data.settings.validatingCssClass + ' ' + data.settings.errorCssClass + ' ') $errorElement.removeClass(data.settings.validatingCssClass + ' ' + data.settings.errorCssClass + ' ')
.addClass(data.settings.successCssClass); .addClass(data.settings.successCssClass);
} }
attribute.value = getValue($form, attribute); attribute.value = getValue($form, attribute);
} }
$form.trigger(events.afterValidateAttribute, [attribute, messages[attrib ute.id]]); $form.trigger(events.afterValidateAttribute, [attribute, messages[attrib ute.id]]);
return hasError; return hasError;
}; };
/** /**
skipping to change at line 879 skipping to change at line 887
} }
}; };
var getValue = function ($form, attribute) { var getValue = function ($form, attribute) {
var $input = findInput($form, attribute); var $input = findInput($form, attribute);
var type = $input.attr('type'); var type = $input.attr('type');
if (type === 'checkbox' || type === 'radio') { if (type === 'checkbox' || type === 'radio') {
var $realInput = $input.filter(':checked'); var $realInput = $input.filter(':checked');
if ($realInput.length > 1) { if ($realInput.length > 1) {
var values = []; var values = [];
$realInput.each(function(index) { $realInput.each(function (index) {
values.push($($realInput.get(index)).val()); values.push($($realInput.get(index)).val());
}); });
return values; return values;
} }
if (!$realInput.length) { if (!$realInput.length) {
$realInput = $form.find('input[type=hidden][name="' + $input.att r('name') + '"]'); $realInput = $form.find('input[type=hidden][name="' + $input.att r('name') + '"]');
} }
return $realInput.val(); return $realInput.val();
 End of changes. 24 change blocks. 
44 lines changed or deleted 56 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)