npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery-restful

v0.0.7

Published

Restful form handling with jQuery Use to make a form RESTful friendly GET, POST, DELETE methods, Intercept when leaving page with unsaved data ##Usage

Downloads

1

Readme

jquery-restful

Restful form handling with jQuery Use to make a form RESTful friendly GET, POST, DELETE methods, Intercept when leaving page with unsaved data ##Usage

initialize form var $myform = $("form") $myform.restful();

load data into form, url is required

$myform.restful("JSON", "/some/uri/") 

save data from form, url is optional.

$myform.restful("submit", "/some/uri/")

or

$myform.submit()

or, have a submit button on the form. The submit event is watched and canceled.

The url used to POST:

  1. the provided url
  2. the url set in the options
  3. the action attribute on the form

reset the form

$myform.restful("reset") 

delete data on server using the DELETE method. The same url is determined as with POST

$myform.restful("remove", "/some/uri/")

Any fields with a ".exclude" class are ignored when loading data or submitting data. However changes to them will still trigger an intercept

##Options

{
    message: "You have unsaved changes.",
    intercept: true, 
    onValidate: function($elem, data){return true;},
    onSubmit: function($elem, data){}, 
    onFail: function($elem, data){ alert("An error occurred while saving the data."); },
    onReset: function(){},
    onDelete: function($elem, data){},
    toJSON: function($elem){},
    fromJSON: function(data){},
    onLoad: function($elem, data){},
    uri: ""
}

intercept if false user will not get warning if leaving page with unsaved changes

message message to display in intercept

onValidate function to execute before submitting form. The element is the first argument passed and data to be submitted is the second argument. If function must return true for form to be submitted

onSubmit function to execute on successful submission. Can be used to close/hide form refresh other data, etc.

onFail function

onReset function

onDelete function

toJSON function must return on object or data string suitable for jQuery.post data argument.

Built in function will create a hierarchical object. It filters the form elements as such $elem.find(":input:not(.exclude, button, :submit, :reset)").

Field names of the sort events[start], events[stop] would create an object like:

{events: {start: value1, stop: value2}}

fromJSON function will receive the data to load into the form. The context is the jQuery form element. ie this.find(":input").

Note the built in function filters the form elements as such this.find(":input:not(.exclude, button, :submit, :reset)") and follows the same hierarchy as toJSON

onLoad function to run after data from server is loaded into form. Can be used to clean up data, or to manipulate the form as needed. This function is not called when a data object is provided.

uri -optional- the url to use for submit and remove actions. If not provided the form action will be used

Note: the onValidate, onSubmit, onFail, onReset, onDelete functions are all called in the context of the restful object. This exposes this.dirty and this.element. To prevent the page intercept set this.dirty to false.