How jQuery Editable Works
jQuery Editable consist of 3 elements:
- Parent Element
- Display Element
- Input Field/Element
The structure is like this:
<span>
<label></label>
<input />
</span>
In this case span is Parent Element, label is Display Element and input is Input Element.
* Span and label and input can be changed to any tag you want "that's why it is so flexible".
* Parent element is not mandatory it is needed in case you want the Input Element to be displayed in same position as Display Element.
Display Element has two extra attributes called data-type="editable" and data-for="css selector for Input Element".
The above code can be something like this:
<span>
<label data-type="editable" data-for=".input1">Click me to change!</label>
<input class='input1'/>
</span>
And when you call $('body').editables(); it will detect all editables in defined scope "body" and make them to act as editable. See more add sample page at the end of page.
$('body').editables( { editOn: 'mouseover' } );
jQuery Editable Options
This plugin get 6 options:
- editOn: [event | array[events] ] Any valid jQuery Event: click, dblclick, mouseover, ... Default is 'click'.
- beforeEdit: [function(inputField, ev){} ] This function is called before converting the display to input field. "this" keywords in this fucntion refers to display element.
- onEdit: [function] This function is bound to display element as an event.
- freezeOn: [event | array[events] ] Any valid jQuery Event: click, dblclick, mouseover, ... Default is 'blur'.
- beforeFreeze: [function(display, ev){} ] This function is called
before converting the input field to display. "this" keywords in this
fucntion refers to input field.
- onFreeze: [function] This function is bound to input field element as an event.
jQuery Editable (changing options globally)
All these options are declared at $.fn.editables.options which means you can override them before start using them "which takes global effect".
$.fn.editables.options.beforeEdit = function(field){
field.val(this.text());
return true;
}
$.extend(
$.fn.editables.options.beforeEdit,
{
editOn: 'mouseover',
beforeEdit: function(inp){
if(inp.val()=='') return false; /*this prevent the conversion to editable*/
}
}
)
Download
Here is the link to Download jQuery inline Editable Plugin 1.0.1 and here is Sample for jQuery Editable.
If you need any feature to be added or have any question, please use below comment box.
Older version
jQuery Editable 1.0.0
jQuery Plugins with this Pattern
Lite jQuery Watermark (Placeholder) plugin with same pattern click here.
Flexible jQuery Validation (validator) plugin with same pattern click here.
Tue, 07 24 2012
How can i set the freezeOn at the press of the "ENTER" key ?
I upgraded the plugin. So in case, you want to bind more than one event, now you can pass an array
and in case you want to have it for on Enter
beforeFreeze: function(display, ev){ if( ev.which!=13 ) return false; }I added an example in example page too.
Now it's on github https://github.com/tectual/jQuery-Editable
$('edit-icon-selector').click( function(){ $('particular-editable-selector').click() } )Sure in case the element is editable on mouseover or any other event, you should replace .click() with the right one.
pre
$('#my-editable-item).edit()
pre
$('edit-icon-selector').click( function(){ $('particular-editable-selector').trigger('startEditing') } )to trigger the 'startEditing' event. In case you need more info, you can email us at tectual.com.au.something is preventing propagation or the blur event is forwhatever reason not firing after edit on input.
I screwed it all up somehow.
Thanks for replying.