Automatically persist your forms' text and select field values locally, until the form is submitted.

Overview

Garlic.js

Build Status

Garlic.js allows you to automatically persist your forms' text and select field values locally, until the form is submitted. This way, your users don't lose any precious data if they accidentally close their tab or browser.

Demonstration / Documentation

http://garlicjs.org/

Version

1.4.2

See CHANGELOG for more info.

TODO

  • Improve doc and api;
  • Refactorize some code;
  • Work on inputs radio and textarea where there are conflicts;
  • And much more, for fun!

Run tests

  • In your browser: go to tests/index.html
  • Headless tests: npm install && npm test

Make production minified versions

You'll need ruby, and Google Closure compiler: gem install closure-compiler. Then, just call:

./bin/build.sh version where version is the build release. eg: ./bin/build.sh 1.1.2

They'll be created and dumped in the dist/ directory

Contributors

  • @cdmoyer
  • @johnrees
  • @Marfa
  • @leondewey
  • @willdurand
  • @nashby

Used / Inspiration

Licence

MIT - See LICENCE.md

Comments
  • Form emptied on submit, resulting in invalid form

    Form emptied on submit, resulting in invalid form

    @guillaumepotier while testing #105 on staging, another form we use Garlic on gets emptied / destroyed before submit. As a result of that no data is sent, and the form validation does not pass as the CQRF token also is cleared.

    Narrowed this down to comparing 1.2.4 to 1.3.0, on which the bug occurs (so is not specific to PR #105 ): https://github.com/guillaumepotier/Garlic.js/compare/1.2.4...master

    The form initialization used to be like this:

    $(function() {
        $('#orderInfoForm').garlic({
            excluded: '[data-persist="false"]'
        });
    });
    

    and restoring the form to a working situation was possible by:

    $(function() {
        $('#orderInfoForm').garlic();
    });
    

    We now see that the form is emptied, but that the form submit works. I think the form should not be emptied, but only the storage should be emptied right?

    opened by rvanlaak 13
  • [Edited]Please add ability to turn on conflictManager with data attribute, and make it turned off by default

    [Edited]Please add ability to turn on conflictManager with data attribute, and make it turned off by default

    This issue is changed already Read the discussion yourself :)

    === Original issue content Sometimes when i refresh a form I got some strange hint "This is your saved data. Click here to see default one"

    Can I set option to disable it or choose other behavior? (I just want the hint gone) It's screwing the layout:(

    I will disable it for the moment :S But thanks for the rest of the work!

    opened by PikachuEXE 12
  • Added number, tel and email to the list of default fields.

    Added number, tel and email to the list of default fields.

    What do you think?

    It caught me out that those did not work out of the box...

    Want me to add the rest of the html5 field types? number and tell change the on screen keyboard on a mobile so they are needed for mobile stuff.

    opened by leondewey 10
  • Add support for select

    Add support for select

    Not sure if you want to support select elements, but this seemed like a missing feature to me, since it' felt weird to return the page and have it almost resume the previous state.

    Also binding to some additional events instead of just keyUp, since a paste event, for example, can change the content without touching a key.

    opened by cdmoyer 9
  • IE 8 data mixing

    IE 8 data mixing

    Video @ https://docs.google.com/open?id=0B0emwt_fpZvddFNqQWJ5WVNfZVE

    SO issue: http://stackoverflow.com/questions/13489224/how-to-implement-node-localname-equivalent-for-ie8

    bug ongoing 
    opened by Marfa 8
  • Add `pre` events to override storing and restoring

    Add `pre` events to override storing and restoring

    This allows us to add a timestamp to the data, so we can locally configure whether we want to use outdated values.

    Example

    $('#garlicForm').garlic({
            # ...
            preRetrieve: function(elem, currentValue, restoredValue) {
                var cacheValue = JSON.parse(restoredValue);
                if (cacheValue.timestamp < getLastDateModified()) {
                    return false;
                }
                return cacheValue.content;
            },
            prePersist: function(elem, storedValue) {
                var timestamp = getCurrentTimestamp();
                return parseCacheItem(timestamp, storedValue);
            }
        });
    

    Fixes #93

    opened by rvanlaak 5
  • Fixed issue where data-storage=

    Fixed issue where data-storage="false" would stick.

    I fixed a bug where if you had a field with data-storage="false" the rest of the form would also be data-storage="false" from that point onward.

    I have not created the .min.js file sorry. What are you using todo that, I keep getting a larger file.

    bug ongoing 
    opened by leondewey 5
  • Does it work with Angular.js

    Does it work with Angular.js

    I have a scenario where after user fill out a form FBSDK call is made to check if the user is authenticated. If not, FB authenticates himself and gets redirected back to the form but by then the information is lost.

    I used data-persist="garlic" on the form but ti didn't work. Am I missing something?

    opened by vinodsobale 4
  • Add onSwap handler.

    Add onSwap handler.

    Hi Guillaume,

    I faced an need to execute own functions after swap event. So I suggest to implement an option for such handler.

    In particular is essential for widget overridden by some js wrapper. F.e CKeditor.

    opened by vitaliitkachenko 4
  • Form submit always clears local storage

    Form submit always clears local storage

    When submitting the form, data in local storage is always cleared, regardless of whether the form submit goes ahead (i.e. even if the form fails validation).

    So, in a form using both Garlic.js and Parsley.js, if you fill in all fields and hit submit (but with an invalid entry), then the data is cleared. I would expect (hope) that data is only cleared once the form submits and validates, otherwise data is cleared too early.

    opened by edmelly 4
  • Fix select multiple

    Fix select multiple

    add support for select[multiple] instead of silently failing. every value will be converted to JSON before it is saved to local storage to support the array value of select[multiple].

    opened by nintra 3
  • "Cannot read property 'fn' of undefined" with webpack

    In the past I used Garlic.js with great success, but now that I use webpack to compile my assets, I get this error in the browser console:

    garlic.min.js:145 Uncaught TypeError: Cannot read property 'fn' of undefined
        at garlic.min.js:145
        at Object../node_modules/garlicjs/dist/garlic.min.js (garlic.min.js:197)
        at __webpack_require__ (bootstrap:19)
        at Module.<anonymous> (application.js:17)
        at Module../app/javascript/packs/application.js (application.js:32)
        at __webpack_require__ (bootstrap:19)
        at bootstrap:83
        at bootstrap:83
    (anonymous) @ garlic.min.js:145
    ./node_modules/garlicjs/dist/garlic.min.js @ garlic.min.js:197
    __webpack_require__ @ bootstrap:19
    (anonymous) @ application.js:17
    ./app/javascript/packs/application.js @ application.js:32
    __webpack_require__ @ bootstrap:19
    (anonymous) @ bootstrap:83
    (anonymous) @ bootstrap:83
    

    My entry point contains this:

    require('garlicjs')
    

    And it does not matter whether I change this to:

    import 'garlicjs'
    

    I must admit that I am not very good at all at JavaScript, so I would not be surprised if the solution is really simple?

    opened by bovender 1
  • Does not correctly record the field data with the phone type

    Does not correctly record the field data with the phone type

    There is a problem with the input field with the phone type. I use for this field - jquery.maskedinput.js Code for this field: $('body').on('focus', 'input[name='phone']', function(){ $(this).mask('+7 (999) 999-99-99'); }); Everything is fine here. But Garlic.js doesn't work correctly. The value from this field is written without the last digit: "+7 (111) 111-11-1_" Сan you help me with this?

    opened by DmitriyRomanov-front 0
  • Garlic.js integration with TinyMCE Editor error (Using Firefox)

    Garlic.js integration with TinyMCE Editor error (Using Firefox)

    Main Page has a number of tab, after 3-4 tab switchings when I click on the form page and write in TinyMCE editor and click on save the data is not sent to the controller.

    opened by Paras-Gupta790 0
  • Great script. How can I store entire form data?

    Great script. How can I store entire form data?

    I want to export and save all form data into a single json file and then place it back into the form fields if the users loads the app (online test) on a different device.

    Is there an API within garlic to get the entire blob of data and save it remotely to a database like Firebase?

    opened by inglesuniversal 0
Owner
Guillaume Potier
Guillaume Potier
jQuery Form Plugin

jQuery Form Overview The jQuery Form Plugin allows you to easily and unobtrusively upgrade HTML forms to use AJAX. The main methods, ajaxForm and ajax

null 5.2k Jan 3, 2023
Magically convert a simple text input into a cool tag list with this jQuery plugin.

jQuery Tags Input Plugin Do you use tags to organize content on your site? This plugin will turn your boring tag list into a magical input that turns

XOXCO 2.3k Dec 23, 2022
Add Github like mentions autocomplete to your application.

⚠️ Announcement ⚠️ This project was no longer maintained. You could use zurb tribute instead. An autocompletion library to autocomplete mentions, smil

Harold.Luo 5.3k Dec 19, 2022
Add live paragraph-, word- and character-counting to an HTML element.

Countable Countable is a JavaScript function to add live paragraph-, word- and character-counting to an HTML element. Countable is a zero-dependency l

Sacha Schmid 1.6k Dec 2, 2022
typeahead.js is a fast and fully-featured autocomplete library

typeahead.js Inspired by twitter.com's autocomplete search functionality, typeahead.js is a flexible JavaScript library that provides a strong foundat

Twitter 16.5k Jan 4, 2023
jQuery plugin for styling checkboxes and radio-buttons

English description | Описание на русском jQuery-plugin for styling checkboxes and radio-buttons. With skin support. Version: 2.0.0 Project page and d

Denis Ineshin 70 Sep 24, 2022
A set of flat and 3D progress button styles where the button itself serves as a progress indicator

A set of flat and 3D progress button styles where the button itself serves as a progress indicator. 3D styles are used for showing the progress indication on one side of the button while rotating the button in perspective.

Codrops 608 Oct 19, 2022
This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

HtmlFormApp Overview This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreads

Kanshi TANAIKE 18 Oct 23, 2022
Solid Forms provides several form control objects useful for making working with forms easier.

Solid Forms Solid Forms provides several form control objects useful for making working with forms easier. Demos and examples below. # solidjs yarn ad

John 28 Jan 2, 2023
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
A JavaScript library allows showing/hiding "dependent" field(s) if the value of the “dependee” field matches the right condition.

MF Conditional Fields A JavaScript library that show/hide form elements based on the value of one field or many. Advantages Lightweight & fast. Comes

Ali Khallad 11 Aug 11, 2022
Functions for testing the types of JavaScript values, cross-realm. Has testers for all standard built-in objects/values.

@suchipi/is Functions for testing the types of JavaScript values, cross-realm. Has testers for all standard built-in objects/values. Usage import { is

Lily Skye 5 Sep 8, 2022
🛠 Highly customisable, minimalistic input x select field for React.

Insect ?? Highly customisable, minimalistic input x select field for React. ⚡️ Features Tiny size (~4kb Gzip) 100% responsive. Highly customisable. Su

Kadet 32 Oct 29, 2022
A Google Chrome extension that automatically fills in the "CAPTCHA" form element for IISER Pune's SAM portal (Academic ERP) login form

A Google Chrome extension that automatically fills in the "CAPTCHA" form element for IISER Pune's SAM portal (Academic ERP) login form.

Jason 3 Mar 4, 2022
Phonemask - Library for processing the phone input field in the web form. Only native javascript is used

phonemask Library for processing the phone input field in the web form. Only native javascript is used Usage: Adding a library to HTML <script type="a

Neovav 2 Sep 20, 2022
A jquery plugin to determine when a user has stopped typing in a text field.

The official home for the TypeWatch jQuery plugin. TypeWatch calls a function when a user has typed text in an input, textarea and changes in div from

Denny Ferrassoli 221 Nov 3, 2022
This plugin integrates by default with Twitter bootstrap using badges to display the maximum lenght of the field where the user is inserting text. Uses the HTML5 attribute "maxlength" to work.

Bootstrap MaxLength This plugin integrates by default with Twitter bootstrap using badges to display the maximum length of the field where the user is

Maurizio 772 Dec 25, 2022
Next js boilerplate with redux toolkit, redux persist and axios

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Jorge Alberto Villarreal Gongora 5 Apr 25, 2022
Octoprint-Detector2 is a detection plugin that runs in locally your browser and emails you if it detects some spaghetti, stringing or blobs on your print

Octoprint-Detector2 is a detection plugin that runs in locally your browser and emails you if it detects some spaghetti, stringing or blobs on your print. All you need is an email account and a PC.

Mikulash 24 Jan 2, 2023
A pinia plugin for state persist.

Pinia Persists A pinia plugin for state persist. English | 简体中文 Usage Install npm i pinia-persists Use import { persist } from 'pinia-persists' import

Dewey Ou 18 Dec 12, 2022