X-editable overwrite user input from server

Following are two cases:

Case 1:  you want to just display value differently

you can use render event

$('#action').on('render', function(e, editable) {
	var colors = {0: "gray", 1: "green", 2: "blue", 3: "red"};
	$(this).css("color", colors[editable.value]);


Case 2: you want to set value to element which is returned in ajax response instead of what set at client side e.g. uesr inserted value “Hello” but sever converts it into “hello”(small case) then do following

in ajax response set new value e.g. {“success”:true,”pk”:13,”value”:”hello”}

use following code

success:function(data, config) {
	if(typeof(data) == 'object') {
	var api_id = data.pk;
	var success = data.success;
	if(success == true) {
		return {newValue:data.value}

ensure you return object with exact name newValue


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s