Skip to content

Keep inputs, selects, textareas data, even if web page is refreshed

Notifications You must be signed in to change notification settings

gensjaak/keepjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

keepjs

Keep inputs, selects, textareas data, even if web page is refreshed.

Usage

Installation

Include keep.js to your html file

<script type="text/javascript" src="path/to/keep.js"></script>

Method 1

Add keep attribute to the inputs like bellow

<label for="name">
	Enter your name
	<input type="text" name="name" id="name" value="" keep>
</label>

and initialize plugin via Javascript like this

keep()

KeepJS will scan for inputs that have keep in their attributes and will watch data changes.

Method 2

We can also do it only in JS keep([HTMLElement1_ID, HTMLElement2_ID, HTMLElement3_ID, ...HTMLElements_ID]) Strings in array are IDs of the inputs.

keep([
	'birthday',
	'full_name',
	'gender',
	'description',
	'job',
	'favorite_color'
])

Options

In this version (1.0.0) of plugin, only one option is available.

Lazy keeping

Add keep-lazy to the tag or in JS By default, this option is set to true.

keep({
	targets: [ 'birthday', 'full_name', 'gender', 'description', 'job', 'favorite_color' ],
	opts: {
		lazy: Boolean
	}
})

If lazy is falsy, data will be kept on keyup of the inputs.

Multiple keeps

This option will be available soon. By default, this option is set to false. You'll be able to keep more than one value for an tag and choose one when serving data.

Add keep-multiple to the tag or in JS

keep({
	targets: [ 'birthday', 'full_name', 'gender', 'description', 'job', 'favorite_color' ],
	opts: {
		lazy: Boolean,
		multiple: Boolean
	}
})

NOT AVAILABLE IN V-1.0.0

Author

Jean-jacques AKAKPO ([email protected])

An ovaar products