Basics of browser database with Web SQL

In the next example we are going to create a database (to save people parameters for example), insert and replace element, delete a table, and show data from database itself.

You can add new people data using the inputs and pressing “Save in database”, if the inputs have a red border it means you need to fill in before saving.

Editable Selection Box

There is not any specific HTML tag to let you edit and select, we just have input tags and select tags but we can combine them and even more we can define our own icon/button for the select box. The trick here is to launch an event to show up our options from our hidden selection box.

You can adjust the options style, however in mobile apps the select options will be shown by an internal widget of the system.

Updated: you can use an input list with its datalist (Autocomplete dropdown)

Check input using HTML5 and MDL

You can use input’s attributes as min, max, pattern and so on, and then checking a simple class do what you need to. In this example we are using a Text Field component of  Material Design Lite (MDL) which shows a message and a red mark up when the value is not the right one. You could extend this with as many inputs as you like and then if all of them are correct show a login button or whatever.

Note that in old browsers and android versions before Lolipop where the Web View isn’t Chrome you will need to use directly Validation DOM Methods. Ex:

document.querySelector('input').validity.rangeOverflow

Be careful because even some Validation DOM Methods are not well supported in old browsers versions.

Counter with a reset using Closures

Set up a basic counter with a closure and some externally accessible options.

Infinite Scroll

Have you ever seen those automatic “load more” while you scroll down? Did you see them on Tumblr for images, Gmail for messages or Facebook? Cool, isn’t it? The infinite scroll is an alternative for pagination and it’s everywhere. It optimizes the user experience loading data as the user required it (indirectly). You get faster loading process for pages, web, apps and it just loads what you need instead of the whole bunch. You don’t need to add extra interactions, buttons or widgets because it comes with the normal reading behaviour that you are used to: scroll down with the mouse or with the finger in a touchable screen.

So, here how to do it in a simple pure JavaScript 🙂