Coder Social home page Coder Social logo

activeform's Introduction

SETUP
1. Your form must have an ID, which is not included by defult in Rails, 
you can do <% form_for :model, :html => { :id => "model" }, :url...

2. The first class name for each field must be the name of the ActiveFormField type
it should be set as. (class = "select" or class = "phone") See below for a list of
available field types.

3. Set the requirements for each form. If required, include a class name "required".
The order doesn't matter as long as it's not first. (class = "text required")

4. Create an instance of ActiveForm after the page loads. ( var bill = new ActiveForm(form_id); )
The form id should probably be the same as the instance name.

That's it.

Now in your javascript on the page you can do fun stuff like:

Access and set the field value directly.
The form ID is removed from the field id to create the attribute/field name.
user.name("Steve") // Sets name as "Steve"
user.name() // => "Steve" (don't forget the parenthesis () railsers')

Trigger events
user.country_field.after_set = function(value) {
  if(value = "USA") {
    $('user_state_div').show();
  }
}

REFERENCING

Overview
VALUE:    form.attribute();
OBJECT:   form.attribute_field;
ELEMENT:  form.attribute_field.element;

WRONG: user.name().after_set = function() {};
form.attribute() is not the ActiveFormField object. It is just a getter/setter.

RIGHT: user.fields.name.after_set = function() {};
form.fields.attribute is the ActiveFormField object

WRONG: user.fields.name.value;
form.fields.attribute is not the actual input element, it is the ActiveFormField object

RIGHT: user.fields.name.element.value;

Though if you just want the value
RIGHTER: user.name();

NOTES

Choosing to go with the format of form.field.get() instead of
form.attribute() and form.fields.field.get() because I'm finding my self using the field functions
a lot more than I thougth I would.

activeform's People

Contributors

heff avatar

Watchers

 avatar  avatar  avatar

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.