Vizualize.me Google Plus LinkedIn

Freebies

Edit-In-Place jQuery Plugin

This is a “Edit in place” jQuery plugin. It allows you to designate certain portions of text that you want to be able to edit on the fly.

Syntax:

javascript


$(document).ready(function() {
	$('.editInPlace').editInPlace({
		editimg: 'icons/pencil.png',
		editlink: 'Edit This',
		saveimg:'icons/disk.png',
		autosave:function(text){
			$('input[name=editInPlace1]').val(text);
		}
	});

	jQuery('.editTextarea').editInPlace({
		edittype:'textarea',
		edittypeclass:'wysiwyg',
		removeable:true
	});

	jQuery('#eip1').editInPlace('destroy');
});

html


<div class="editInPlace" id="eip1">Edit in place # 1</div>
<div class="editInPlace" id="eip2">Edit in place # 2</div>
<div class="editTextarea" id="eip3">Edit in place # 3</div>
<input type="hidden" name="editInPlace1" value="" />

Configurable options (and their default values):


'edittype':'text' (can be 'text', 'textarea','password'),
'edittypeclass':null (the class to add to the form element),
'editlink':'Edit' (the text of the edit link that shows up beside the editable text),
'editimg':null (the path to the edit image to use instead of the 'editlink' text - if set, 'editlink' will be ignored),
'removelink':'Remove' (if a set of text if removable, this is the text of the remove link),
'removeimg': null (path to the remove image to use instead of 'removelink' text),
'removeable':false (set to true to allow text to be removeable),
'savelink':'Save' (the Save link text for when the text is done being changed),
'saveimg':null (save image instead of savelink text),
'cancellink':'Cancel' (the Cancel link to change text back to original text and convert back to text instead of in 'edit' mode),
'cancelimg':null (cancel image to use instead of cancellink text),
'autosave': null (a function that gets called when the "save" link is clicked)

Form DMZ Extension

DMZ (DataMapper, OverZealous Edition) is an ORM for the CodeIgniter PHP Framework (currently maintained by Wanwizard).

This extension provides a function to convert a DMZ object into the associative array needed for CodeIgniter‘s form_dropdown function provided by the Form Helper.

The extension only requires one parameter (the field to use as the text for each select option), and has one optional parameter (the field to use as the value of each option – defaults to ‘id’).

Example use:



//using default id
$actors = new actor();
$actors->get();
form_dropdown('actor',$actors->to_dropdown_array('name'));
 
//using specified id
$books = new book();
$books->get();
form_dropdown('book',$books->to_dropdown_array('title','isbn'));

To use this DMZ extension:

  • download it (from the link below)
  • add it to your application/datamapper directory
  • add ‘form’ to the $config['extensions'] array in the application/config/datamapper.php file.

As of today (June 9, 2011), that is the only function available in this extension, but I would like to add to it. If you have any ideas on what I can/should add, please leave me a comment below requesting it, and some details about what it should do.

UPDATE (Jun 14, 2011): This function can now output the multi-dimensional array needed by CI’s form_dropdown function for option groups.

Here’s the breakdown:
Regular drop down (no groups)


$books = new book();
$books->get();
form_dropdown('book',$books->to_dropdown_array('title'));
//just pass in the string value of the field you want to use as the text of the options
 
$books = new book();
$books->get();
form_dropdown('book',$books->to_dropdown_array(array('binding'=>'title')));
// pass in an assoc array, with key being field to use for grouping, and value being the field to use for text of the options
 
$books = new book();
$books->get();
form_dropdown('book',$books->to_dropdown_array(array('author.name'=>'title')));
// pass in an assoc array, with key being dot notation of related model [dot] field (for the grouping), and value being the field to use for the text of the options.

In all cases, the second parameter of the function is the field to use as the value of the options (what gets sent through $_POST).

You can also leave comments or questions about it in general. So, feel free!