How to design editable listview using jQuery Mobile plugin?
Last Updated :
15 Dec, 2020
In this article, we will learn how to design an editable listview feature using the jQuery mobile plugin. The plugin provides an intuitive user interface to add or delete list items to the existing list.
To design and implement the plugin, please download the required pre-compiled files or libraries from the link and save it in your working folder. The file path names should be taken care of while coding.
Note: Please use the following links in the head section of the HTML code for execution as shown below.
<link href=”http://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.2/jquery.mobile.css”
rel=”stylesheet” type=”text/css”/><link href=”editable-listview.css”
rel=”stylesheet” type=”text/css”/><script src=”http://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.2/jquery.mobile.js”></script> <script src=”http://code.jquery.com/jquery-2.1.1.js”></script>
<script src=”editable-listview.js”></script>
Example 1: The following example demonstrates a simple editable listview using the jQuery mobile plugin. The user can add and delete fruit names in the list as shown in the below output.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1" />
<link rel="stylesheet"
href=
"http://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.2/jquery.mobile.css"/>
<link rel="stylesheet" href="editable-listview.css"/>
<script src=
"http://code.jquery.com/jquery-2.1.1.js">
</script>
<script src=
"http://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.2/jquery.mobile.js">
</script>
<script src="editable-listview.js"></script>
</head>
<body style="padding: 20px;">
<h2>jQuery Mobile Editable Listview</h2>
<div style="padding: 20px;">
<ul id="mylistID" data-role="listview"
data-item-name="fruitName">
<li>Pineapple</li>
<li>Mango</li>
<li>Orange</li>
<li>Banana</li>
</ul>
<br />
</div>
<script>
var $list = $("#mylistID").listview({
editable: true,
title: "Fruits",
emptyTitle: "No Fruits",
});
</script>
</body>
</html>
Output:

Example 2: The following example demonstrates another editable listview with some added properties. The form “id” should match the data-editable-form attribute on the “ul” tag and the data-editable attribute is set to “true”.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1"/>
<link rel="stylesheet"
href=
"http://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.2/jquery.mobile.css"/>
<link rel="stylesheet" href="editable-listview.css" />
<script src=
"http://code.jquery.com/jquery-2.1.1.js">
</script>
<script src=
"http://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.2/jquery.mobile.js">
</script>
<script src="editable-listview.js"></script>
</head>
<body style="padding: 20px;">
<h2>jQuery Mobile editable listview</h2>
<div style="padding: 20px;">
<p><strong>Complex Editable Listview</strong></p>
<ul id="list" data-role="listview"
data-editable="true"
data-editable-type="complex"
data-editable-form="editing-formID"
data-title="Vegetables"
data-empty-title="No Veggies">
<li>
<a>
<h3>
<span id="veggieName">
Potato
</span>
</h3>
<p>
<em>Shape:</em>
<strong>
<span id="veggieShape">
round
</span>
</strong>
</p>
<p>
<em>Color:</em>
<strong>
<span id="veggieColor">
brown
</span>
</strong>
</p>
</a>
</li>
<li>
<a>
<h3><span id="veggieName">
Brinjal
</span>
</h3>
<p>
<em>Shape:</em>
<strong>
<span id="veggieShape">
oval
</span>
</strong>
</p>
<p>
<em>Color:</em>
<strong>
<span id="veggieColor">
purple
</span>
</strong>
</p>
</a>
</li>
<li>
<a>
<h3><span id="veggieName">
Tomato
</span>
</h3>
<p>
<em>Shape:</em>
<strong>
<span id="veggieShape">
round
</span>
</strong>
</p>
<p>
<em>Color:</em>
<strong>
<span id="veggieColor">
red
</span>
</strong>
</p>
</a>
</li>
</ul>
<form id="editing-formID"
data-editable-form="true">
<input type="text"
data-item-name="veggieName"
data-item-template="<h3>
<span id='veggieName'>%%</span>
</h3>"/>
<input
type="text"
data-item-name="veggieShape"
data-item-template="<p><em>Shape:</em>
<strong><span id='veggieShape'>%%</span>
</strong></p>"/>
<input
type="text"
data-item-name="veggieColor"
data-item-template="<p><em>Color:</em>
<strong><span id='veggieColor'>%%</span>
</strong></p>"/>
<button class="ui-btn ui-corner-all"
data-add-button="true">
Add
</button>
<button class="ui-btn ui-corner-all"
data-clear-button="true">
Clear
</button>
</form>
</div>
<script>
var $list = $("#list").listview({
editable: true,
editableType: "simple",
title: "Veggies",
emptyTitle: "No Veggies",
});
</script>
</body>
</html>
Output:

Similar Reads
How to design filter widget for mobiles using jQuery plugin ? In this article, we will learn how to design a filterable widget for the user interface of mobile applications using the jQuery filter bar plugin. The plugin works with many HTML controls like select, buttons, tables, control groups.Download the required pre-compiled files from this link and save it
2 min read
How to design menu using jQuery EasyUI Mobile ? In this article, we will learn how to design menu list using jQuery EasyUI Mobile plugin. EasyUI is a HTML5 framework for using user interface components based on jQuery, React, Angular and Vue technologies. It helps in building features for interactive web and mobile applications saving a lot of ti
2 min read
How to create Unordered listviews using jQuery Mobile ? jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be making unordered listviews using jQuery Mobile. Approach: First, add jQuery mobile scripts needed for your project. <link rel="styles
1 min read
How to create Filtered Ordered listviews using jQuery Mobile ? jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating Filtered Ordered listviews using jQuery Mobile. Approach: First, add jQuery Mobile scripts needed for your project. <link rel
1 min read
jQuery Mobile Listview disabled Option jQuery Mobile is an HTML5 based user interface system designed to make responsive websites and apps that are accessible on all smartphone, tablet, and desktop devices. jQuery Listview is a widget used to create beautiful lists. It is a simple and responsive listview used to view the unordered lists.
2 min read
jQuery Mobile Listview initSelector Option jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be using the jQuery Mobile Listview initSelector option. The value of this option is a selector string that picks elements on the basis of
2 min read