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

riot-form

v0.2.0

Published

Form inputs for RiotJS

Downloads

5

Readme

riot-form Build Status

Easy forms for riotjs.

A set of classes and tags to generate and handle forms.

Installation

You can either include the files in dist or require.

With npm

npm install riot-form --save

With bower

bower install riot-form --save

Usage

Example with automatic rendering

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8"/>
    <title>simple.html</title>

  </head>
  <body>

    <app></app>

    <script type="riot/tag">
      <app>
        <rf-form model="{ form }" class-name="custom-class">
          <input type="submit" value="Save">
        </rf-form>

        <div class="output">
          Username: <span class="username">{ form.model.username }</span>
          Profile: <span class="profile">{ form.model.profile }</span>
        </div>

        this.form = new riotForm.Form.Builder('simple')
                                .addInput({name: 'username', type: 'text'})
                                .addInput({name: 'profile', type: 'textarea'})
                                .setModel({username: 'Daniel', profile: 'My name is Daniel'})
                                .build();

        this.form.on('change', () => this.update())
      </app>
    </script>

    <script src="./components/riot/riot+compiler.js"></script>
    <script src="./js/riot-form.js"></script>

    <script>
      riot.mount('app')
    </script>
  </body>
</html>

Example with manual rendering

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8"/>
    <title>simple.html</title>

  </head>
  <body>

    <app></app>

    <script type="riot/tag">
      <app>
        <form name="{ form.name }" onsubmit="{ doSomething }">
          <rf-text-input model="{ form.inputs.username }" autofocus>
          <rf-textarea-input model="{ form.inputs.profile }">
          <input type="submit" value="Save">
        </form>

        <div class="output">
          Username: <span class="username">{ form.model.username }</span>
          Profile: <span class="profile">{ form.model.profile }</span>
        </div>

        this.form = new riotForm.Form.Builder('simple')
                                .addInput({name: 'username', type: 'text'})
                                .addInput({name: 'profile', type: 'textarea'})
                                .setModel({username: 'Daniel', profile: 'My name is Daniel'})
                                .build();


        this.doSomething = function () {
          console.log(this.form.model);
        }.bind(this);

        this.form.on('change', () => this.update())
      </app>
    </script>

    <script src="./components/riot/riot+compiler.js"></script>
    <script src="./js/riot-form.js"></script>

    <script>
      riot.mount('app')
    </script>
  </body>
</html>

Note that in both cases, the form.model property will always be synchronized with the content of the form.

API

riotForm.Form

Form.prototype

  • name: Returns the name of the form, included in the config
  • inputs: Returns all the inputs of the form as an object
  • model: Returns the model of the form
  • errors: Returns an object with the errors of the form
  • valid: Returns a boolean with true if the form is valid and false otherwise

Form.Builder

  • addInput: Add an input to the form. It can be any object with a name and a type properties You can pass a tag as an option to change the tag that will be rendered for this input
  • setModel: Set the form model. form values will be populated with it
  • build: Construct the form and returns a Form instance.

By default, the model will be cloned when building the form, to avoid overriding existing values. If you want the values model of the you pass to be changed, pass {noClone: true} to the build method.

How to

Registering new inputs

You will probably want to create new inputs to fit your needs.

You can easily do so by creating a subclass of riotForm.BaseInput and registering it as follow.

With ES5

// ES5
var riotForm = require('riot-form')

var MyInput = riotForm.BaseInput.extend({
  myFunc: function () {
    return 'whatever you want'
  }
})

MyInput.type       = 'my-type'
MyInput.defaultTag = 'my-tag'

riotForm.inputFactory.register(MyInput)

or with ES6

// ES6
import {BaseInput, inputFactory} from 'riot-form'
class MyInput extends BaseInput {
  myFunc() {
    return 'whatever you want'
  }
}

MyInput.type       = 'my-type'
MyInput.defaultTag = 'my-tag'

inputFactory.register(MyInput)