MINOR Moved jsparty/jquery/jquery_improvements.js to sapphire/javascript/jquery_improvements.js

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@93589 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-11-26 04:33:23 +00:00 committed by Sam Minnee
parent fad4957687
commit 7ab1932864

34
javascript/jquery_improvements.js vendored Normal file
View File

@ -0,0 +1,34 @@
// play nice with prototype
jQuery.noConflict();
/**
* Clears the selected form elements. Takes the following actions on the matched elements:
* - input text fields will have their 'value' property set to the empty string
* - select elements will have their 'selectedIndex' property set to -l. Normann change it from -1 to '',
* since set to -1, actually is not clearing the field, it change its value to null, and when submit the form the field belonged to,
* the field value will be treated to a pure string "null", and this is not what it suppose to do.
* - checkbox and radio inputs will have their 'checked' property set to false
* - inputs of type submit, button, reset, and hidden will *not* be effected
* - button elements will *not* be effected
*
* @example $('.myInputs').clearFields();
* @desc Clears all inputs with class myInputs
*
* @name clearFields
* @type jQuery
* @cat Plugins/Form
*/
(function($) {
$.fn.clearFields = $.fn.clearInputs = function() {
return this.each(function() {
var t = this.type, tag = this.tagName.toLowerCase();
if (t == 'text' || t == 'password' || tag == 'textarea')
this.value = '';
else if (t == 'checkbox' || t == 'radio')
this.checked = false;
else if (tag == 'select')
//changed by Normann@silvestripe.com, see document above
this.selectedIndex = '';
});
};
})(jQuery);