address inpt autosubmit method
This commit is contained in:
parent
5c1ebaaf5e
commit
5b18620b99
src
@ -26,14 +26,24 @@ $(function(){
|
|||||||
this.init('address', options, Address.defaults);
|
this.init('address', options, Address.defaults);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//inherit from Abstract input
|
||||||
$.fn.editableutils.inherit(Address, $.fn.editabletypes.abstract);
|
$.fn.editableutils.inherit(Address, $.fn.editabletypes.abstract);
|
||||||
|
|
||||||
$.extend(Address.prototype, {
|
$.extend(Address.prototype, {
|
||||||
render: function() {
|
/**
|
||||||
Address.superclass.render.call(this);
|
Renders input from tpl
|
||||||
},
|
|
||||||
|
@method render()
|
||||||
|
**/
|
||||||
|
render: function() {
|
||||||
|
Address.superclass.render.call(this);
|
||||||
|
},
|
||||||
|
|
||||||
//standard way to show value in element. Used only if display option not defined.
|
/**
|
||||||
|
Default method to show value in element. Can be overwritten by display option.
|
||||||
|
|
||||||
|
@method value2html(value, element)
|
||||||
|
**/
|
||||||
value2html: function(value, element) {
|
value2html: function(value, element) {
|
||||||
if(!value) {
|
if(!value) {
|
||||||
$(element).empty();
|
$(element).empty();
|
||||||
@ -43,12 +53,17 @@ $(function(){
|
|||||||
$(element).html(html);
|
$(element).html(html);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Gets value from element's html
|
||||||
|
|
||||||
|
@method html2value(html)
|
||||||
|
**/
|
||||||
html2value: function(html) {
|
html2value: function(html) {
|
||||||
/*
|
/*
|
||||||
you may write parsing method to get value by element's html
|
you may write parsing method to get value by element's html
|
||||||
e.g. "Moscow, st. Lenina, bld. 15" => {city: "Moscow", street: "Lenina", building: "15"}
|
e.g. "Moscow, st. Lenina, bld. 15" => {city: "Moscow", street: "Lenina", building: "15"}
|
||||||
but for complex structures I do not recommend do that.
|
but for complex structures it's not recommended.
|
||||||
Better always set value directly via javascript, e.g.
|
Better set value directly via javascript, e.g.
|
||||||
editable({
|
editable({
|
||||||
value: {
|
value: {
|
||||||
city: "Moscow",
|
city: "Moscow",
|
||||||
@ -60,10 +75,12 @@ $(function(){
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/**
|
||||||
converts value to string.
|
Converts value to string.
|
||||||
It is used in internal comparing (not for sending to server).
|
It is used in internal comparing (not for sending to server).
|
||||||
*/
|
|
||||||
|
@method value2str(value)
|
||||||
|
**/
|
||||||
value2str: function(value) {
|
value2str: function(value) {
|
||||||
var str = '';
|
var str = '';
|
||||||
if(value) {
|
if(value) {
|
||||||
@ -75,19 +92,35 @@ $(function(){
|
|||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
this is mainly for parsing value defined in data-value attribute.
|
Converts string to value. Used for reading value from 'data-value' attribute.
|
||||||
If you will always set value by javascript, no need to overwrite it
|
|
||||||
|
@method str2value(str)
|
||||||
*/
|
*/
|
||||||
str2value: function(str) {
|
str2value: function(str) {
|
||||||
|
/*
|
||||||
|
this is mainly for parsing value defined in data-value attribute.
|
||||||
|
If you will always set value by javascript, no need to overwrite it
|
||||||
|
*/
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets value of input.
|
||||||
|
|
||||||
|
@method value2input(value)
|
||||||
|
@param {mixed} value
|
||||||
|
**/
|
||||||
value2input: function(value) {
|
value2input: function(value) {
|
||||||
this.$input.find('input[name="city"]').val(value.city);
|
this.$input.find('input[name="city"]').val(value.city);
|
||||||
this.$input.find('input[name="street"]').val(value.street);
|
this.$input.find('input[name="street"]').val(value.street);
|
||||||
this.$input.find('input[name="building"]').val(value.building);
|
this.$input.find('input[name="building"]').val(value.building);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns value of input.
|
||||||
|
|
||||||
|
@method input2value()
|
||||||
|
**/
|
||||||
input2value: function() {
|
input2value: function() {
|
||||||
return {
|
return {
|
||||||
city: this.$input.find('input[name="city"]').val(),
|
city: this.$input.find('input[name="city"]').val(),
|
||||||
@ -95,11 +128,28 @@ $(function(){
|
|||||||
building: this.$input.find('input[name="building"]').val()
|
building: this.$input.find('input[name="building"]').val()
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Activates input: sets focus on the first field.
|
||||||
|
|
||||||
|
@method activate()
|
||||||
|
**/
|
||||||
activate: function() {
|
activate: function() {
|
||||||
//set focus on city
|
|
||||||
this.$input.find('input[name="city"]').focus();
|
this.$input.find('input[name="city"]').focus();
|
||||||
}
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Attaches handler to submit form in case of 'showbuttons=false' mode
|
||||||
|
|
||||||
|
@method autosubmit()
|
||||||
|
**/
|
||||||
|
autosubmit: function() {
|
||||||
|
this.$input.find('input[type="text"]').keydown(function (e) {
|
||||||
|
if (e.which === 13) {
|
||||||
|
$(this).closest('form').submit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Address.defaults = $.extend({}, $.fn.editabletypes.abstract.defaults, {
|
Address.defaults = $.extend({}, $.fn.editabletypes.abstract.defaults, {
|
||||||
|
@ -26,7 +26,7 @@ To create your own input you should inherit from this class.
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Renders input. Can return jQuery deferred object.
|
Renders input from tpl. Can return jQuery deferred object.
|
||||||
|
|
||||||
@method render()
|
@method render()
|
||||||
**/
|
**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user