JSFiddle - React, Tailwind, and code Playground
by itsazzad
HTML
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css">
<link rel="stylesheet" href="http://vitalets.github.com/x-editable/assets/x-editable/bootstrap-editable/css/bootstrap-editable.css">
<script src="http://vitalets.github.com/x-editable/assets/x-editable/bootstrap-editable/js/bootstrap-editable.js"></script>
<script src="http://vitalets.github.com/x-editable/assets/mockjax/jquery.mockjax.js"></script>
<div style="width:300px;text-align:center;margin:200px auto; 0"> <span data-pk="1" data-type="location" class="content" id="location"></span>
</div>
CSS
.editable-location span {
width: 60px;
display: inline-block;
}
JavaScript
(function ($) {
"use strict";
var Location = function (options) {
this.sourceCountryData = options.sourceCountry;
this.init('location', options, Location.defaults);
};
//inherit from Abstract input
$.fn.editableutils.inherit(Location, $.fn.editabletypes.abstractinput);
$.extend(Location.prototype, {
render: function () {
this.$input = this.$tpl.find('input');
this.$list = this.$tpl.find('select');
this.$list.empty();
var fillItems = function ($el, data) {
if ($.isArray(data)) {
for (var i = 0; i < data.length; i++) {
if (data[i].children) {
$el.append(fillItems($('<optgroup>', {
label: data[i].text
}), data[i].children));
} else {
$el.append($('<option>', {
value: data[i].value
}).text(data[i].text));
}
}
}
return $el;
};
fillItems(this.$list, this.sourceCountryData);
},
value2html: function (value, element) {
if (!value) {
$(element).empty();
return;
}
var countryText = value.country;
$.each(this.sourceCountryData, function (i, v) {
if (v.value == countryText) {
countryText = v.text.toUpperCase();
}
});
var html = $('<div>').text(value.city).html() + ' / ' + $('<div>').text(countryText).html();
$(element).html(html);
},
html2value: function (html) {
return null;
},
value2str: function (value) {
var str = '';
if (value) {
for (var k in...