jQuery + KnockOut = Awesome Forms

1 4 19th 2012 § 0 comments

A fun little Newsletter generator I am working on that uses KnockOut and jQuery in magical and new amazing ways! It is kinda ugly right now, because it is still in process–so shut up.

Knockout: (you only get a sample, you don’t need to see all of the crazy)


// let's list out the images to select
function f_imgBig()
{
	var newArray = Array();
	newArray.push(

	"images/366_A.jpg",
	"images/366_B.jpg",
	"images/366_C.jpg",
	"images/366_D.jpg",
	"images/366_E.jpg",
	"images/366_none.jpg"
	);

	return newArray;
}

function f_imgBigSel()
{
	var newArray = Array();
	newArray = f_imgBig() ;

	return newArray[0];
}
// now let's add in the viewModel and sorting
var viewModel = {}; // always outside of the document load
$(function() {

<!-- drag drop sort -->
	$( "#leftA,#leftB,#leftC" ).sortable({ connectWith: ['#leftA','#leftB','#leftC'] });

<!-- VIEW -->

viewModel = {
	postList_L: ko.observableArray( leftPost() ),
        addPost_L: function () {
	this.postList_L.push({
		img	: f_imgBig(),
		imgSel	: ko.observable(f_imgBigSel())
	});},

ko.applyBindings(viewModel);

});

Here is the html template.
(yes I am using tables, don’t worry about it)

<pre><!-- LEFT -->
    <table data-bind="visible: postList_L().length > 0" bgcolor="#FFFFFF">

        <tr><td id="module_area">

        <ul data-bind='template: { xxxxxxxx id="leftB" ></ul>

        <ul data-bind='template: { name: "postTemplate_L", foreach: postList_L }' id="leftA" ></ul>

        <ul data-bind='template: { xxxxxxxx id="leftC" ></ul>

        </td></tr>

    </table>

    <input name="AddPost" type="image" src="_css/img/20.gif" data-bind="click: addPost_L" id="addPost">

<!-- post -->
	<script type="text/html" id="postTemplate_L">
        <li style="background:#EFE;" id="sel">
        <div id="mov"></div>
		<input name="del" type="image" src="_css/img/20.gif" 
data-bind="click: function(){ viewModel.removePost_L($data); }, 
visible: viewModel.postList_L().length > 1" id="del">

		<input type="image" data-bind="attr: { src: imgSel }" />
		<select data-bind="options: img, value: imgSel" />

        </li>
    </script></pre>

Tagged , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

What's this?

You are currently reading jQuery + KnockOut = Awesome Forms at DrPunchBlog.

meta

  •  

    January 2012
    M T W T F S S
    « Dec   Feb »
     1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031  
  • Archives

  • The Uber-Mannerist ...
    By Van Arno
  • RSS mtr.me

    • Unions Plan Strike Against Spike TV’s ’1,000 Ways To Die’
      Freelance author Dominic Patten is a Deadline contributor. Spike TV’s 1,000 Ways To Die competence shortly learn what it’s like to be The Biggest Loser. Teamsters Local 399 and IATSE pronounced currently that they devise to take movement opposite 1,000 Ways writer Original Productions over organisation members dismissed final week. The unions did a same thin […]
    • NUKEMAP: So You’ll Know What To Expect If Your House Ever Gets Atomic Bombed
      NUKEMAP is a Google Maps application created by probable militant Alex Wellerstein to daydream a area influenced if a nuclear bomb was forsaken in your neighborhood. You only select a distance of a atomic explosve you wish to dump (or a chronological preset), enter an residence (or drag a nuke icon) and BOOOOOM, all you’ve […]
    • University of Michigan connoisseur architecture…
      *kechan University of Michigan connoisseur design students give a empty Detroit storefront a lead facelift. #46316 Article source: http://www.notcot.org/post/46316/ […]
  • Translator