daukantas / activeform Goto Github PK
View Code? Open in Web Editor NEWThis project forked from heff/activeform
Prototype form helper
Home Page: http://www.sevenwire.com
This project forked from heff/activeform
Prototype form helper
Home Page: http://www.sevenwire.com
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.