|
|
@ -7,10 +7,8 @@ var _t = instance.web._t; |
|
|
|
|
|
|
|
instance.web.form.FieldText.include({ |
|
|
|
template: 'FieldText', |
|
|
|
LIMIT_LINES_CONTEXT_KEY: 'limit_lines', |
|
|
|
LIMIT_LINES_DEFAULT: 10, |
|
|
|
LIMIT_CHARS_CONTEXT_KEY: 'limit_chars', |
|
|
|
LIMIT_CHARS_DEFAULT: 500, |
|
|
|
LIMIT_LINES_CONTEXT_KEY: 'maxlines', |
|
|
|
LIMIT_CHARS_CONTEXT_KEY: 'maxlength', |
|
|
|
|
|
|
|
events: { |
|
|
|
'keyup': function (e) { |
|
|
@ -25,31 +23,45 @@ instance.web.form.FieldText.include({ |
|
|
|
limit_value: function($textarea) |
|
|
|
{ |
|
|
|
var ctx = this.build_context().eval(); |
|
|
|
var limit_lines = ctx[this.LIMIT_LINES_CONTEXT_KEY]*1 |
|
|
|
if (!limit_lines){ |
|
|
|
limit_lines = this.LIMIT_LINES_DEFAULT; |
|
|
|
console.log("No default values found for limit lines in '" |
|
|
|
+ this.name + "' field. Default value " + limit_lines |
|
|
|
+ " will be used."); |
|
|
|
} |
|
|
|
|
|
|
|
var limit_chars = ctx[this.LIMIT_CHARS_CONTEXT_KEY]*1 |
|
|
|
if (!limit_chars){ |
|
|
|
limit_chars = this.LIMIT_CHARS_DEFAULT; |
|
|
|
console.log("No default values found for limit chars in '" |
|
|
|
+ this.name + "' field. Default value " + limit_chars |
|
|
|
+ " will be used."); |
|
|
|
} |
|
|
|
var maxlines = ctx[this.LIMIT_LINES_CONTEXT_KEY]*1 |
|
|
|
var maxlength = ctx[this.LIMIT_CHARS_CONTEXT_KEY]*1 |
|
|
|
|
|
|
|
var value = $textarea.val(); |
|
|
|
var lines = value.split("\n"); |
|
|
|
if (lines.length > limit_lines){ |
|
|
|
$textarea.val(lines.slice(0, limit_lines).join("\n")); |
|
|
|
|
|
|
|
if (maxlines && lines.length > maxlines){ |
|
|
|
$textarea.val(lines.slice(0, maxlines).join("\n")); |
|
|
|
} |
|
|
|
if (maxlength && value.length > maxlength){ |
|
|
|
$textarea.val(value.slice(0, maxlength)); |
|
|
|
} |
|
|
|
if (value.length > limit_chars){ |
|
|
|
$textarea.val(value.slice(0, limit_chars)); |
|
|
|
this.$el.find('span.length_limit').html(value.length + '/' + maxlength); |
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
instance.web.form.FieldChar.include({ |
|
|
|
template: 'FieldChar', |
|
|
|
LIMIT_CHARS_CONTEXT_KEY: 'maxlength', |
|
|
|
|
|
|
|
events: { |
|
|
|
'keyup': function (e) { |
|
|
|
this.limit_value($(e.target)); |
|
|
|
}, |
|
|
|
'change textarea': 'store_dom_value', |
|
|
|
}, |
|
|
|
|
|
|
|
limit_value: function($textarea) |
|
|
|
{ |
|
|
|
var ctx = this.build_context().eval(); |
|
|
|
var maxlength = ctx[this.LIMIT_CHARS_CONTEXT_KEY]*1 |
|
|
|
|
|
|
|
var value = $textarea.val(); |
|
|
|
|
|
|
|
if (maxlength && value.length > maxlength){ |
|
|
|
$textarea.val(value.slice(0, maxlength)); |
|
|
|
} |
|
|
|
this.$el.find('span.length_limit').html(value.length + '/' + limit_chars); |
|
|
|
this.$el.find('span.length_limit').html(value.length + '/' + maxlength); |
|
|
|
}, |
|
|
|
|
|
|
|
}); |