Git Product home page Git Product logo

jquerymobile-editablelistview's Introduction

Editable Listview (jQuery Mobile Plugin)

A customized version of the jQuery Mobile Listview Widget that supports insertion of new list items and removal of existing list items out of the box.

Editable Listview Plugin

Why

Many a times, you come across a situation where you want to allow editing of list items. To do this simple task, you have to build extra functionality around the Listview widget to allow for insertion of new list items and removal of existing list items. Editable Listview plugin is designed to take the pain out of this situaiton by having all this functionality baked-in.

Features

  1. Allows insertion of new list items right in the Listview.
  2. Allows easy removal of existing list items.

Installation

  1. Pick any one of the following way.

    • Download and unzip the package into your project folder (Scroll up and you will see the "Download ZIP" button on the right side).

    • Install using bower.

      bower install jqm-editable-istview

    • Use the CDN hosted version.

      js: //cdn.jsdelivr.net/jquery.editable-listview/x.y.z/jqm.editable.listview.min.js
      css: //cdn.jsdelivr.net/jquery.editable-listview/x.y.z/jqm.editable.listview.min.css

      where x.y.z is the version number.

  2. Include the javascript file after the jQuery Mobile javascript file. Similarly include the stylesheet after the jQuery Mobile stylesheet

How to Use it?

The listview comes in two flavors: simple and complex. Their usage is described below.

Simple Type

Use the following HTML/DOM structure

<ul data-role="listview" data-editable="true">
    <li>Apple</li>
    <li>Banana</li>
    <li>Cranberry</li>
    <li>Cherry</li>
</ul>

See below for a full list of available "data-" attributes

Complex Type

For complex type, link a form to the listview through data-editable-form attribute by putting in the id of the form as the value. That form will be shown embedded in the collapsible listview in Edit Mode. The user is at liberty to make the form look however they feel like, but they are supposed to add some specific data attributes to form elements. See the working example below.

<ul data-role="listview" data-editable="true" data-editable-type="complex" data-editable-form="editing-form" data-title="Fruits" data-empty-title="No Fruits">
    <li>
        <a>
            <h3><span id="fruitName">Apple</span></h3>
            <p><em>Shape:</em> <strong><span id="fruitShape">round</span></strong></p>
            <p><em>Color:</em> <strong><span id="fruitColor">red</span></strong></p>
        </a>
    </li>
    <li>
        <a>
            <h3><span id="fruitName">Pineapple</span></h3>
            <p><em>Shape:</em> <strong><span id="fruitShape">oval</span></strong></p>
            <p><em>Color:</em> <strong><span id="fruitColor">yellow</span></strong></p>
        </a>
    </li>
    <li>
        <a>
            <h3><span id="fruitName">Orange</span></h3>
            <p><em>Shape:</em> <strong><span id="fruitShape">round</span></strong></p>
            <p><em>Color:</em> <strong><span id="fruitColor">orange</span></strong></p>
        </a>
    </li>
</ul>

<form id="editing-form" data-editable-form="true">
    <input type="text" data-item-name="fruitName" data-item-template="<h3><span id='fruitName'>%%</span></h3>">
    <input type="text" data-item-name="fruitShape" data-item-template="<p><em>Shape:</em> <strong><span id='fruitShape'>%%</span></strong></p>">
    <input type="text" data-item-name="fruitColor" data-item-template="<p><em>Color:</em> <strong><span id='fruitColor'>%%</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>

data-item-name is the name of the variable to hold the value of the input field.

data-item-template holds the HTML template that will be used to render the new value. Use %% as placeholder for the variable. data-add-button indicates the button that can be clicked/tapped/pressed to insert the new list item having values specified in the input fields. data-clear-button clears all the text from the input fields.

Roadmap

This is a preliminary list of planned fatures.

  1. In-place editing of existing list items.
  2. Re-ordering of list items tap and hold on the list item and drag it back and forth.
  3. Deleting item by swiping left or right.

List of data- Attributes

See the List of data attributes wiki page.

License

Copyright ยฉ 2014 โ€“ 2015 Wasif Hasan Baig

Source code is released under the Terms and Conditions of MIT License.

Please refer to the License file in the source code project directory.

jquerymobile-editablelistview's People

Contributors

baig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jquerymobile-editablelistview's Issues

AJAX call on add/edit

Can I add ajax calls to add and delete buttons? If yes, can you please provide an example?

Also, Will this plugin work in mobile only since it uses jquery mobile?

Programmatically Appending List Items

I'm using Cordova, and trying to append to the list programmatically, using:
$('#list').append("<li>item</li>");

Unfortunately, behavior seems to be dependent on the timing of the call. If I try to append after the entire page is loaded, the list fails to register it as an item. In particular, if I append during a the "deviceready" event, it adds to the list fine, however, if I call it during a "pagebeforeshow", it adds the item to the list container visually - but not the list itself.

I've attached screenshots to demonstrate what I mean. Notice, that after clicking edit, the items not belonging to the list disappear.
Before clicking edit:
beforeclickingedit
After clicking edit:
afterclickingedit

The error is replicable.

On a side note:
The style issue in the screenshots, where the plus is not inline with the textbox seems to only occur in the iOS simulator, and not on the device - so I do not believe it is an issue.

using a select element in form (complex list)

Is there any inherent reason why one of the form inputs in a complex list cannot be a select list (i.e., a dropdown menu)? Regular text inputs seem to work fine, but I haven't been able to get a select list to work yet. There is no error; when I click the Add button, nothing happens.

 <ul data-role="listview" data-editable="true" data-editable-type="complex" data-editable-form="editing-form" data-title="Partners" data-empty-title="No Partners">

Here is the html for the form:

<form id="editing-form" data-editable-form="true">

<input type="text" data-item-name="partnerNames" data-item-template="<h3 id='partnerNames'>Names: %%</h3>"></div>

<select data-item-name="partnerType" data-item-template="<p id='partnerType'>Type: %%<p>" name="partner-type"><option value="1">Alumni</option>
<option value="2">Businesses</option>
<option value="3">Community Groups</option>
<option value="4">Educators/Schools</option><option value="6">Government</option>
<option value="5">Health Care</option><option value="7">Media</option>
</select>
 <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>

And the list item html (done as a foreach loop):

 <li class="names">
 <h3 id="partnerNames">Names:$partner-names</h3>
 <p id="partnerType">Type: $partner-type</p>
 </li>

Not working on real devices?

Hi,

Great widget! If I take the demo index.html and access from a real device (android/apple) there seems to be a problem. The list expansion and collapse works just fine unless you made an edit. Once you make an edit you can't collapse the list. It works just fine when trying from a laptop. Is it just me?

Thanks,

Douglas.

Implement destroy

Implement the destroy function

  • Cache the unenhanced DOM structure when creating/initializing listview
  • Keep track of list items that are added or removed
  • Restore the unenhanced DOM along with the recent state of the list and its items (only if it was enhanced by the plugin)

Editable Listview within a JQM "page": Cannot read property '0' of undefined

I'm using the JQuery Mobile pages widget to display several form elements. one at a time. Each element uses a database query to display the current database value (if any) in the form upon load.

I have one element that utilizes Editable Listview. When the the database value is not empty, it displays just fine. But if the database value is empty, I get this error in the JS console:

Uncaught error: Cannot read property '0' of undefined

It points to line 161 in EditableListview:

// Re-enabling the click event handler when the list is in View mode
evt.click[0].handler = this._clickHandler;
evt.tap[0].handler = this._tapHandler;

Do you know what might be happening here, and how I might get around it?

Great plugin, by the way!

,

please delete this!

In place editing of list items

In edit mode when the user taps on the list item, the list item should be replaced with a text box with the list item value as shown in the mockup below.

el-mockup

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.