/
jquery.autofill.js
44 lines (35 loc) · 1.64 KB
/
jquery.autofill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Author - Harshen Pandey
* Version - 1.6.0
* Release - 5th June 2017
* Copyright (c) 2017 - 2020 Harshen Pandey
*/
(function( $ ) {
$.fn.autofill = function( options ) {
//Giving default value for fieldId option.
$.fn.autofill.defaults.fieldId = this.attr('id') + "_copy";
return this.each( function() {
autofillboxes( $(this), options );
});
};
//Definition of private function autofillboxes.
function autofillboxes( $this , options ) {
var opts = $.extend( {}, $.fn.autofill.defaults, options );
var $this = $this;
$this.blur( function() {
if(( options.fieldId == undefined && options.overrideFieldEverytime == undefined ) || ( options.fieldId == undefined && options.overrideFieldEverytime == false ) || ( options.fieldId != undefined && options.overrideFieldEverytime == undefined ) || ( options.fieldId != undefined && options.overrideFieldEverytime == false )) {
if( $( "#" + opts.fieldId ).val() == "" ) {
$( "#" + opts.fieldId ).val( $this.val() );
$this.unbind('blur');
}
}
else if(( options.fieldId == undefined && options.overrideFieldEverytime == true ) || ( options.fieldId != undefined && options.overrideFieldEverytime == true )) {
$( "#" + opts.fieldId ).val( $this.val() );
}
});
};
//Giving default value for overrideFieldEverytime option.
$.fn.autofill.defaults = {
overrideFieldEverytime : false
};
}(jQuery));