You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

712 line
29KB

  1. /**
  2. * Yii form widget.
  3. *
  4. * This is the JavaScript widget used by the yii\widgets\ActiveForm widget.
  5. *
  6. * @link http://www.yiiframework.com/
  7. * @copyright Copyright (c) 2008 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. * @author Qiang Xue <qiang.xue@gmail.com>
  10. * @since 2.0
  11. */
  12. (function ($) {
  13. $.fn.yiiActiveForm = function (method) {
  14. if (methods[method]) {
  15. return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
  16. } else if (typeof method === 'object' || !method) {
  17. return methods.init.apply(this, arguments);
  18. } else {
  19. $.error('Method ' + method + ' does not exist on jQuery.yiiActiveForm');
  20. return false;
  21. }
  22. };
  23. var events = {
  24. /**
  25. * beforeValidate event is triggered before validating the whole form.
  26. * The signature of the event handler should be:
  27. * function (event, messages, deferreds)
  28. * where
  29. * - event: an Event object.
  30. * - messages: an associative array with keys being attribute IDs and values being error message arrays
  31. * for the corresponding attributes.
  32. * - deferreds: an array of Deferred objects. You can use deferreds.add(callback) to add a new deferred validation.
  33. *
  34. * If the handler returns a boolean false, it will stop further form validation after this event. And as
  35. * a result, afterValidate event will not be triggered.
  36. */
  37. beforeValidate: 'beforeValidate',
  38. /**
  39. * afterValidate event is triggered after validating the whole form.
  40. * The signature of the event handler should be:
  41. * function (event, messages, errorAttributes)
  42. * where
  43. * - event: an Event object.
  44. * - messages: an associative array with keys being attribute IDs and values being error message arrays
  45. * for the corresponding attributes.
  46. * - errorAttributes: an array of attributes that have validation errors. Please refer to attributeDefaults for the structure of this parameter.
  47. */
  48. afterValidate: 'afterValidate',
  49. /**
  50. * beforeValidateAttribute event is triggered before validating an attribute.
  51. * The signature of the event handler should be:
  52. * function (event, attribute, messages, deferreds)
  53. * where
  54. * - event: an Event object.
  55. * - attribute: the attribute to be validated. Please refer to attributeDefaults for the structure of this parameter.
  56. * - messages: an array to which you can add validation error messages for the specified attribute.
  57. * - deferreds: an array of Deferred objects. You can use deferreds.add(callback) to add a new deferred validation.
  58. *
  59. * If the handler returns a boolean false, it will stop further validation of the specified attribute.
  60. * And as a result, afterValidateAttribute event will not be triggered.
  61. */
  62. beforeValidateAttribute: 'beforeValidateAttribute',
  63. /**
  64. * afterValidateAttribute event is triggered after validating the whole form and each attribute.
  65. * The signature of the event handler should be:
  66. * function (event, attribute, messages)
  67. * where
  68. * - event: an Event object.
  69. * - attribute: the attribute being validated. Please refer to attributeDefaults for the structure of this parameter.
  70. * - messages: an array to which you can add additional validation error messages for the specified attribute.
  71. */
  72. afterValidateAttribute: 'afterValidateAttribute',
  73. /**
  74. * beforeSubmit event is triggered before submitting the form after all validations have passed.
  75. * The signature of the event handler should be:
  76. * function (event)
  77. * where event is an Event object.
  78. *
  79. * If the handler returns a boolean false, it will stop form submission.
  80. */
  81. beforeSubmit: 'beforeSubmit',
  82. /**
  83. * ajaxBeforeSend event is triggered before sending an AJAX request for AJAX-based validation.
  84. * The signature of the event handler should be:
  85. * function (event, jqXHR, settings)
  86. * where
  87. * - event: an Event object.
  88. * - jqXHR: a jqXHR object
  89. * - settings: the settings for the AJAX request
  90. */
  91. ajaxBeforeSend: 'ajaxBeforeSend',
  92. /**
  93. * ajaxComplete event is triggered after completing an AJAX request for AJAX-based validation.
  94. * The signature of the event handler should be:
  95. * function (event, jqXHR, textStatus)
  96. * where
  97. * - event: an Event object.
  98. * - jqXHR: a jqXHR object
  99. * - textStatus: the status of the request ("success", "notmodified", "error", "timeout", "abort", or "parsererror").
  100. */
  101. ajaxComplete: 'ajaxComplete'
  102. };
  103. // NOTE: If you change any of these defaults, make sure you update yii\widgets\ActiveForm::getClientOptions() as well
  104. var defaults = {
  105. // whether to encode the error summary
  106. encodeErrorSummary: true,
  107. // the jQuery selector for the error summary
  108. errorSummary: '.error-summary',
  109. // whether to perform validation before submitting the form.
  110. validateOnSubmit: true,
  111. // the container CSS class representing the corresponding attribute has validation error
  112. errorCssClass: 'has-error',
  113. // the container CSS class representing the corresponding attribute passes validation
  114. successCssClass: 'has-success',
  115. // the container CSS class representing the corresponding attribute is being validated
  116. validatingCssClass: 'validating',
  117. // the GET parameter name indicating an AJAX-based validation
  118. ajaxParam: 'ajax',
  119. // the type of data that you're expecting back from the server
  120. ajaxDataType: 'json',
  121. // the URL for performing AJAX-based validation. If not set, it will use the the form's action
  122. validationUrl: undefined,
  123. // whether to scroll to first visible error after validation.
  124. scrollToError: true
  125. };
  126. // NOTE: If you change any of these defaults, make sure you update yii\widgets\ActiveField::getClientOptions() as well
  127. var attributeDefaults = {
  128. // a unique ID identifying an attribute (e.g. "loginform-username") in a form
  129. id: undefined,
  130. // attribute name or expression (e.g. "[0]content" for tabular input)
  131. name: undefined,
  132. // the jQuery selector of the container of the input field
  133. container: undefined,
  134. // the jQuery selector of the input field under the context of the form
  135. input: undefined,
  136. // the jQuery selector of the error tag under the context of the container
  137. error: '.help-block',
  138. // whether to encode the error
  139. encodeError: true,
  140. // whether to perform validation when a change is detected on the input
  141. validateOnChange: true,
  142. // whether to perform validation when the input loses focus
  143. validateOnBlur: true,
  144. // whether to perform validation when the user is typing.
  145. validateOnType: false,
  146. // number of milliseconds that the validation should be delayed when a user is typing in the input field.
  147. validationDelay: 500,
  148. // whether to enable AJAX-based validation.
  149. enableAjaxValidation: false,
  150. // function (attribute, value, messages, deferred, $form), the client-side validation function.
  151. validate: undefined,
  152. // status of the input field, 0: empty, not entered before, 1: validated, 2: pending validation, 3: validating
  153. status: 0,
  154. // whether the validation is cancelled by beforeValidateAttribute event handler
  155. cancelled: false,
  156. // the value of the input
  157. value: undefined
  158. };
  159. var submitDefer;
  160. var setSubmitFinalizeDefer = function($form) {
  161. submitDefer = $.Deferred();
  162. $form.data('yiiSubmitFinalizePromise', submitDefer.promise());
  163. };
  164. // finalize yii.js $form.submit
  165. var submitFinalize = function($form) {
  166. if(submitDefer) {
  167. submitDefer.resolve();
  168. submitDefer = undefined;
  169. $form.removeData('yiiSubmitFinalizePromise');
  170. }
  171. };
  172. var methods = {
  173. init: function (attributes, options) {
  174. return this.each(function () {
  175. var $form = $(this);
  176. if ($form.data('yiiActiveForm')) {
  177. return;
  178. }
  179. var settings = $.extend({}, defaults, options || {});
  180. if (settings.validationUrl === undefined) {
  181. settings.validationUrl = $form.attr('action');
  182. }
  183. $.each(attributes, function (i) {
  184. attributes[i] = $.extend({value: getValue($form, this)}, attributeDefaults, this);
  185. watchAttribute($form, attributes[i]);
  186. });
  187. $form.data('yiiActiveForm', {
  188. settings: settings,
  189. attributes: attributes,
  190. submitting: false,
  191. validated: false,
  192. target: $form.attr('target')
  193. });
  194. /**
  195. * Clean up error status when the form is reset.
  196. * Note that $form.on('reset', ...) does work because the "reset" event does not bubble on IE.
  197. */
  198. $form.bind('reset.yiiActiveForm', methods.resetForm);
  199. if (settings.validateOnSubmit) {
  200. $form.on('mouseup.yiiActiveForm keyup.yiiActiveForm', ':submit', function () {
  201. $form.data('yiiActiveForm').submitObject = $(this);
  202. });
  203. $form.on('submit.yiiActiveForm', methods.submitForm);
  204. }
  205. });
  206. },
  207. // add a new attribute to the form dynamically.
  208. // please refer to attributeDefaults for the structure of attribute
  209. add: function (attribute) {
  210. var $form = $(this);
  211. attribute = $.extend({value: getValue($form, attribute)}, attributeDefaults, attribute);
  212. $form.data('yiiActiveForm').attributes.push(attribute);
  213. watchAttribute($form, attribute);
  214. },
  215. // remove the attribute with the specified ID from the form
  216. remove: function (id) {
  217. var $form = $(this),
  218. attributes = $form.data('yiiActiveForm').attributes,
  219. index = -1,
  220. attribute = undefined;
  221. $.each(attributes, function (i) {
  222. if (attributes[i]['id'] == id) {
  223. index = i;
  224. attribute = attributes[i];
  225. return false;
  226. }
  227. });
  228. if (index >= 0) {
  229. attributes.splice(index, 1);
  230. unwatchAttribute($form, attribute);
  231. }
  232. return attribute;
  233. },
  234. // manually trigger the validation of the attribute with the specified ID
  235. validateAttribute: function (id) {
  236. var attribute = methods.find.call(this, id);
  237. if (attribute != undefined) {
  238. validateAttribute($(this), attribute, true);
  239. }
  240. },
  241. // find an attribute config based on the specified attribute ID
  242. find: function (id) {
  243. var attributes = $(this).data('yiiActiveForm').attributes,
  244. result = undefined;
  245. $.each(attributes, function (i) {
  246. if (attributes[i]['id'] == id) {
  247. result = attributes[i];
  248. return false;
  249. }
  250. });
  251. return result;
  252. },
  253. destroy: function () {
  254. return this.each(function () {
  255. $(this).unbind('.yiiActiveForm');
  256. $(this).removeData('yiiActiveForm');
  257. });
  258. },
  259. data: function () {
  260. return this.data('yiiActiveForm');
  261. },
  262. // validate all applicable inputs in the form
  263. validate: function () {
  264. var $form = $(this),
  265. data = $form.data('yiiActiveForm'),
  266. needAjaxValidation = false,
  267. messages = {},
  268. deferreds = deferredArray(),
  269. submitting = data.submitting;
  270. var event = $.Event(events.beforeValidate);
  271. $form.trigger(event, [messages, deferreds]);
  272. if (submitting) {
  273. if (event.result === false) {
  274. data.submitting = false;
  275. submitFinalize($form);
  276. return;
  277. }
  278. }
  279. // client-side validation
  280. $.each(data.attributes, function () {
  281. if (!$(this.input).is(":disabled")) {
  282. this.cancelled = false;
  283. // perform validation only if the form is being submitted or if an attribute is pending validation
  284. if (data.submitting || this.status === 2 || this.status === 3) {
  285. var msg = messages[this.id];
  286. if (msg === undefined) {
  287. msg = [];
  288. messages[this.id] = msg;
  289. }
  290. var event = $.Event(events.beforeValidateAttribute);
  291. $form.trigger(event, [this, msg, deferreds]);
  292. if (event.result !== false) {
  293. if (this.validate) {
  294. this.validate(this, getValue($form, this), msg, deferreds, $form);
  295. }
  296. if (this.enableAjaxValidation) {
  297. needAjaxValidation = true;
  298. }
  299. } else {
  300. this.cancelled = true;
  301. }
  302. }
  303. }
  304. });
  305. // ajax validation
  306. $.when.apply(this, deferreds).always(function() {
  307. // Remove empty message arrays
  308. for (var i in messages) {
  309. if (0 === messages[i].length) {
  310. delete messages[i];
  311. }
  312. }
  313. if ($.isEmptyObject(messages) && needAjaxValidation) {
  314. var $button = data.submitObject,
  315. extData = '&' + data.settings.ajaxParam + '=' + $form.attr('id');
  316. if ($button && $button.length && $button.attr('name')) {
  317. extData += '&' + $button.attr('name') + '=' + $button.attr('value');
  318. }
  319. $.ajax({
  320. url: data.settings.validationUrl,
  321. type: $form.attr('method'),
  322. data: $form.serialize() + extData,
  323. dataType: data.settings.ajaxDataType,
  324. complete: function (jqXHR, textStatus) {
  325. $form.trigger(events.ajaxComplete, [jqXHR, textStatus]);
  326. },
  327. beforeSend: function (jqXHR, settings) {
  328. $form.trigger(events.ajaxBeforeSend, [jqXHR, settings]);
  329. },
  330. success: function (msgs) {
  331. if (msgs !== null && typeof msgs === 'object') {
  332. $.each(data.attributes, function () {
  333. if (!this.enableAjaxValidation || this.cancelled) {
  334. delete msgs[this.id];
  335. }
  336. });
  337. updateInputs($form, $.extend(messages, msgs), submitting);
  338. } else {
  339. updateInputs($form, messages, submitting);
  340. }
  341. },
  342. error: function () {
  343. data.submitting = false;
  344. submitFinalize($form);
  345. }
  346. });
  347. } else if (data.submitting) {
  348. // delay callback so that the form can be submitted without problem
  349. setTimeout(function () {
  350. updateInputs($form, messages, submitting);
  351. }, 200);
  352. } else {
  353. updateInputs($form, messages, submitting);
  354. }
  355. });
  356. },
  357. submitForm: function () {
  358. var $form = $(this),
  359. data = $form.data('yiiActiveForm');
  360. if (data.validated) {
  361. // Second submit's call (from validate/updateInputs)
  362. data.submitting = false;
  363. var event = $.Event(events.beforeSubmit);
  364. $form.trigger(event);
  365. if (event.result === false) {
  366. data.validated = false;
  367. submitFinalize($form);
  368. return false;
  369. }
  370. updateHiddenButton($form);
  371. return true; // continue submitting the form since validation passes
  372. } else {
  373. // First submit's call (from yii.js/handleAction) - execute validating
  374. setSubmitFinalizeDefer($form);
  375. if (data.settings.timer !== undefined) {
  376. clearTimeout(data.settings.timer);
  377. }
  378. data.submitting = true;
  379. methods.validate.call($form);
  380. return false;
  381. }
  382. },
  383. resetForm: function () {
  384. var $form = $(this);
  385. var data = $form.data('yiiActiveForm');
  386. // Because we bind directly to a form reset event instead of a reset button (that may not exist),
  387. // when this function is executed form input values have not been reset yet.
  388. // Therefore we do the actual reset work through setTimeout.
  389. setTimeout(function () {
  390. $.each(data.attributes, function () {
  391. // Without setTimeout() we would get the input values that are not reset yet.
  392. this.value = getValue($form, this);
  393. this.status = 0;
  394. var $container = $form.find(this.container);
  395. $container.removeClass(
  396. data.settings.validatingCssClass + ' ' +
  397. data.settings.errorCssClass + ' ' +
  398. data.settings.successCssClass
  399. );
  400. $container.find(this.error).html('');
  401. });
  402. $form.find(data.settings.errorSummary).hide().find('ul').html('');
  403. }, 1);
  404. },
  405. /**
  406. * Updates error messages, input containers, and optionally summary as well.
  407. * If an attribute is missing from messages, it is considered valid.
  408. * @param messages array the validation error messages, indexed by attribute IDs
  409. * @param summary whether to update summary as well.
  410. */
  411. updateMessages: function (messages, summary) {
  412. var $form = $(this);
  413. var data = $form.data('yiiActiveForm');
  414. $.each(data.attributes, function () {
  415. updateInput($form, this, messages);
  416. });
  417. if (summary) {
  418. updateSummary($form, messages);
  419. }
  420. },
  421. /**
  422. * Updates error messages and input container of a single attribute.
  423. * If messages is empty, the attribute is considered valid.
  424. * @param id attribute ID
  425. * @param messages array with error messages
  426. */
  427. updateAttribute: function(id, messages) {
  428. var attribute = methods.find.call(this, id);
  429. if (attribute != undefined) {
  430. var msg = {};
  431. msg[id] = messages;
  432. updateInput($(this), attribute, msg);
  433. }
  434. }
  435. };
  436. var watchAttribute = function ($form, attribute) {
  437. var $input = findInput($form, attribute);
  438. if (attribute.validateOnChange) {
  439. $input.on('change.yiiActiveForm', function () {
  440. validateAttribute($form, attribute, false);
  441. });
  442. }
  443. if (attribute.validateOnBlur) {
  444. $input.on('blur.yiiActiveForm', function () {
  445. if (attribute.status == 0 || attribute.status == 1) {
  446. validateAttribute($form, attribute, true);
  447. }
  448. });
  449. }
  450. if (attribute.validateOnType) {
  451. $input.on('keyup.yiiActiveForm', function (e) {
  452. if ($.inArray(e.which, [16, 17, 18, 37, 38, 39, 40]) !== -1 ) {
  453. return;
  454. }
  455. if (attribute.value !== getValue($form, attribute)) {
  456. validateAttribute($form, attribute, false, attribute.validationDelay);
  457. }
  458. });
  459. }
  460. };
  461. var unwatchAttribute = function ($form, attribute) {
  462. findInput($form, attribute).off('.yiiActiveForm');
  463. };
  464. var validateAttribute = function ($form, attribute, forceValidate, validationDelay) {
  465. var data = $form.data('yiiActiveForm');
  466. if (forceValidate) {
  467. attribute.status = 2;
  468. }
  469. $.each(data.attributes, function () {
  470. if (this.value !== getValue($form, this)) {
  471. this.status = 2;
  472. forceValidate = true;
  473. }
  474. });
  475. if (!forceValidate) {
  476. return;
  477. }
  478. if (data.settings.timer !== undefined) {
  479. clearTimeout(data.settings.timer);
  480. }
  481. data.settings.timer = setTimeout(function () {
  482. if (data.submitting || $form.is(':hidden')) {
  483. return;
  484. }
  485. $.each(data.attributes, function () {
  486. if (this.status === 2) {
  487. this.status = 3;
  488. $form.find(this.container).addClass(data.settings.validatingCssClass);
  489. }
  490. });
  491. methods.validate.call($form);
  492. }, validationDelay ? validationDelay : 200);
  493. };
  494. /**
  495. * Returns an array prototype with a shortcut method for adding a new deferred.
  496. * The context of the callback will be the deferred object so it can be resolved like ```this.resolve()```
  497. * @returns Array
  498. */
  499. var deferredArray = function () {
  500. var array = [];
  501. array.add = function(callback) {
  502. this.push(new $.Deferred(callback));
  503. };
  504. return array;
  505. };
  506. /**
  507. * Updates the error messages and the input containers for all applicable attributes
  508. * @param $form the form jQuery object
  509. * @param messages array the validation error messages
  510. * @param submitting whether this method is called after validation triggered by form submission
  511. */
  512. var updateInputs = function ($form, messages, submitting) {
  513. var data = $form.data('yiiActiveForm');
  514. if (submitting) {
  515. var errorAttributes = [];
  516. $.each(data.attributes, function () {
  517. if (!$(this.input).is(":disabled") && !this.cancelled && updateInput($form, this, messages)) {
  518. errorAttributes.push(this);
  519. }
  520. });
  521. $form.trigger(events.afterValidate, [messages, errorAttributes]);
  522. updateSummary($form, messages);
  523. if (errorAttributes.length) {
  524. if (data.settings.scrollToError) {
  525. var top = $form.find($.map(errorAttributes, function(attribute) {
  526. return attribute.input;
  527. }).join(',')).first().closest(':visible').offset().top;
  528. var wtop = $(window).scrollTop();
  529. if (top < wtop || top > wtop + $(window).height()) {
  530. $(window).scrollTop(top);
  531. }
  532. }
  533. data.submitting = false;
  534. } else {
  535. data.validated = true;
  536. var buttonTarget = data.submitObject ? data.submitObject.attr('formtarget') : null;
  537. if (buttonTarget) {
  538. // set target attribute to form tag before submit
  539. $form.attr('target', buttonTarget);
  540. }
  541. $form.submit();
  542. // restore original target attribute value
  543. $form.attr('target', data.target);
  544. }
  545. } else {
  546. $.each(data.attributes, function () {
  547. if (!this.cancelled && (this.status === 2 || this.status === 3)) {
  548. updateInput($form, this, messages);
  549. }
  550. });
  551. }
  552. submitFinalize($form);
  553. };
  554. /**
  555. * Updates hidden field that represents clicked submit button.
  556. * @param $form the form jQuery object.
  557. */
  558. var updateHiddenButton = function ($form) {
  559. var data = $form.data('yiiActiveForm');
  560. var $button = data.submitObject || $form.find(':submit:first');
  561. // TODO: if the submission is caused by "change" event, it will not work
  562. if ($button.length && $button.attr('type') == 'submit' && $button.attr('name')) {
  563. // simulate button input value
  564. var $hiddenButton = $('input[type="hidden"][name="' + $button.attr('name') + '"]', $form);
  565. if (!$hiddenButton.length) {
  566. $('<input>').attr({
  567. type: 'hidden',
  568. name: $button.attr('name'),
  569. value: $button.attr('value')
  570. }).appendTo($form);
  571. } else {
  572. $hiddenButton.attr('value', $button.attr('value'));
  573. }
  574. }
  575. };
  576. /**
  577. * Updates the error message and the input container for a particular attribute.
  578. * @param $form the form jQuery object
  579. * @param attribute object the configuration for a particular attribute.
  580. * @param messages array the validation error messages
  581. * @return boolean whether there is a validation error for the specified attribute
  582. */
  583. var updateInput = function ($form, attribute, messages) {
  584. var data = $form.data('yiiActiveForm'),
  585. $input = findInput($form, attribute),
  586. hasError = false;
  587. if (!$.isArray(messages[attribute.id])) {
  588. messages[attribute.id] = [];
  589. }
  590. $form.trigger(events.afterValidateAttribute, [attribute, messages[attribute.id]]);
  591. attribute.status = 1;
  592. if ($input.length) {
  593. hasError = messages[attribute.id].length > 0;
  594. var $container = $form.find(attribute.container);
  595. var $error = $container.find(attribute.error);
  596. if (hasError) {
  597. if (attribute.encodeError) {
  598. $error.text(messages[attribute.id][0]);
  599. } else {
  600. $error.html(messages[attribute.id][0]);
  601. }
  602. $container.removeClass(data.settings.validatingCssClass + ' ' + data.settings.successCssClass)
  603. .addClass(data.settings.errorCssClass);
  604. } else {
  605. $error.empty();
  606. $container.removeClass(data.settings.validatingCssClass + ' ' + data.settings.errorCssClass + ' ')
  607. .addClass(data.settings.successCssClass);
  608. }
  609. attribute.value = getValue($form, attribute);
  610. }
  611. return hasError;
  612. };
  613. /**
  614. * Updates the error summary.
  615. * @param $form the form jQuery object
  616. * @param messages array the validation error messages
  617. */
  618. var updateSummary = function ($form, messages) {
  619. var data = $form.data('yiiActiveForm'),
  620. $summary = $form.find(data.settings.errorSummary),
  621. $ul = $summary.find('ul').empty();
  622. if ($summary.length && messages) {
  623. $.each(data.attributes, function () {
  624. if ($.isArray(messages[this.id]) && messages[this.id].length) {
  625. var error = $('<li/>');
  626. if (data.settings.encodeErrorSummary) {
  627. error.text(messages[this.id][0]);
  628. } else {
  629. error.html(messages[this.id][0]);
  630. }
  631. $ul.append(error);
  632. }
  633. });
  634. $summary.toggle($ul.find('li').length > 0);
  635. }
  636. };
  637. var getValue = function ($form, attribute) {
  638. var $input = findInput($form, attribute);
  639. var type = $input.attr('type');
  640. if (type === 'checkbox' || type === 'radio') {
  641. var $realInput = $input.filter(':checked');
  642. if (!$realInput.length) {
  643. $realInput = $form.find('input[type=hidden][name="' + $input.attr('name') + '"]');
  644. }
  645. return $realInput.val();
  646. } else {
  647. return $input.val();
  648. }
  649. };
  650. var findInput = function ($form, attribute) {
  651. var $input = $form.find(attribute.input);
  652. if ($input.length && $input[0].tagName.toLowerCase() === 'div') {
  653. // checkbox list or radio list
  654. return $input.find('input');
  655. } else {
  656. return $input;
  657. }
  658. };
  659. })(window.jQuery);