Browse Source

[cleanup] santize get_value, fixes frappe/erpnext#9561 (#3624)

version-14
Rushabh Mehta 8 years ago
committed by GitHub
parent
commit
22bf2500dd
6 changed files with 27 additions and 27 deletions
  1. +13
    -14
      frappe/public/js/frappe/form/control.js
  2. +1
    -2
      frappe/public/js/frappe/ui/base_list.js
  3. +3
    -3
      frappe/public/js/frappe/ui/field_group.js
  4. +8
    -6
      frappe/public/js/frappe/ui/filters/filters.js
  5. +1
    -1
      frappe/public/js/frappe/views/calendar/calendar.js
  6. +1
    -1
      frappe/public/js/frappe/views/reports/query_report.js

+ 13
- 14
frappe/public/js/frappe/form/control.js View File

@@ -137,10 +137,10 @@ frappe.ui.form.Control = Class.extend({
this.validate ? this.validate(value, set) : set(value); this.validate ? this.validate(value, set) : set(value);
}); });
}, },
get_parsed_value: function() {
get_value: function() {
if(this.get_status()==='Write') { if(this.get_status()==='Write') {
return this.get_value ?
(this.parse ? this.parse(this.get_value()) : this.get_value()) :
return this.get_input_value ?
(this.parse ? this.parse(this.get_input_value()) : this.get_input_value()) :
undefined; undefined;
} else if(this.get_status()==='Read') { } else if(this.get_status()==='Read') {
return this.value || undefined; return this.value || undefined;
@@ -215,7 +215,6 @@ frappe.ui.form.ControlImage = frappe.ui.form.Control.extend({
this.$body = $("<div></div>").appendTo(this.$wrapper) this.$body = $("<div></div>").appendTo(this.$wrapper)
.css({"margin-bottom": "10px"}) .css({"margin-bottom": "10px"})
this.$wrapper.on("refresh", function() { this.$wrapper.on("refresh", function() {
var doc = null;
me.$body.empty(); me.$body.empty();


var doc = me.get_doc(); var doc = me.get_doc();
@@ -344,7 +343,7 @@ frappe.ui.form.ControlInput = frappe.ui.form.Control.extend({
}, },


set_disp_area: function() { set_disp_area: function() {
let value = this.get_value();
let value = this.get_input_value();
if(in_list(["Currency", "Int", "Float"], this.df.fieldtype) && (this.value === 0 || value === 0)) { if(in_list(["Currency", "Int", "Float"], this.df.fieldtype) && (this.value === 0 || value === 0)) {
// to set the 0 value in readonly for currency, int, float field // to set the 0 value in readonly for currency, int, float field
value = 0; value = 0;
@@ -353,13 +352,13 @@ frappe.ui.form.ControlInput = frappe.ui.form.Control.extend({
} }
this.disp_area && $(this.disp_area) this.disp_area && $(this.disp_area)
.html(frappe.format(value, this.df, {no_icon:true, inline:true}, .html(frappe.format(value, this.df, {no_icon:true, inline:true},
this.doc || (this.frm && this.frm.doc)));
this.doc || (this.frm && this.frm.doc)));
}, },


bind_change_event: function() { bind_change_event: function() {
var me = this; var me = this;
this.$input && this.$input.on("change", this.change || function(e) { this.$input && this.$input.on("change", this.change || function(e) {
me.parse_validate_and_set_in_model(me.get_value(), e);
me.parse_validate_and_set_in_model(me.get_input_value(), e);
}); });
}, },
bind_focusout: function() { bind_focusout: function() {
@@ -465,7 +464,7 @@ frappe.ui.form.ControlData = frappe.ui.form.ControlInput.extend({
set_formatted_input: function(value) { set_formatted_input: function(value) {
this.$input && this.$input.val(this.format_for_input(value)); this.$input && this.$input.val(this.format_for_input(value));
}, },
get_value: function() {
get_input_value: function() {
return this.$input ? this.$input.val() : undefined; return this.$input ? this.$input.val() : undefined;
}, },
format_for_input: function(val) { format_for_input: function(val) {
@@ -919,7 +918,7 @@ frappe.ui.form.ControlCheck = frappe.ui.form.ControlData.extend({
this.set_mandatory(value); this.set_mandatory(value);
this.set_disp_area(); this.set_disp_area();
}, },
get_value: function() {
get_input_value: function() {
if (!this.$input) { if (!this.$input) {
return; return;
} }
@@ -1355,7 +1354,7 @@ frappe.ui.form.ControlLink = frappe.ui.form.ControlData.extend({
new frappe.ui.form.LinkSelector({ new frappe.ui.form.LinkSelector({
doctype: doctype, doctype: doctype,
target: this, target: this,
txt: this.get_value()
txt: this.get_input_value()
}); });
return false; return false;
}, },
@@ -1493,7 +1492,7 @@ frappe.ui.form.ControlLink = frappe.ui.form.ControlData.extend({
me.selected = false; me.selected = false;
return; return;
} }
var value = me.get_value();
var value = me.get_input_value();
if(value!==me.last_value) { if(value!==me.last_value) {
me.parse_validate_and_set_in_model(value); me.parse_validate_and_set_in_model(value);
} }
@@ -1870,13 +1869,13 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({
.attr('data-original-title', ''); .attr('data-original-title', '');
} }
}, },
get_value: function() {
get_input_value: function() {
return this.editor? this.editor.summernote('code'): ''; return this.editor? this.editor.summernote('code'): '';
}, },
set_input: function(value) { set_input: function(value) {
if(value == null) value = ""; if(value == null) value = "";
value = frappe.dom.remove_script_and_style(value); value = frappe.dom.remove_script_and_style(value);
if(value !== this.get_value()) {
if(value !== this.get_input_value()) {
this.set_in_editor(value); this.set_in_editor(value);
} }
this.last_value = value; this.last_value = value;
@@ -2012,7 +2011,7 @@ frappe.ui.form.ControlTable = frappe.ui.form.Control.extend({
return false; return false;
}); });
}, },
get_parsed_value: function() {
get_value: function() {
if(this.grid) { if(this.grid) {
return this.grid.get_data(); return this.grid.get_data();
} }


+ 1
- 2
frappe/public/js/frappe/ui/base_list.js View File

@@ -225,7 +225,6 @@ frappe.ui.BaseList = Class.extend({
}, },


update_standard_filters: function(filters) { update_standard_filters: function(filters) {
let values = {};
let me = this; let me = this;
for(let key in this.page.fields_dict) { for(let key in this.page.fields_dict) {
let field = this.page.fields_dict[key]; let field = this.page.fields_dict[key];
@@ -462,7 +461,7 @@ frappe.ui.BaseList = Class.extend({
set_filter: function (fieldname, label, no_run, no_duplicate) { set_filter: function (fieldname, label, no_run, no_duplicate) {
var filter = this.filter_list.get_filter(fieldname); var filter = this.filter_list.get_filter(fieldname);
if (filter) { if (filter) {
var value = cstr(filter.field.get_parsed_value());
var value = cstr(filter.field.get_value());
if (value.includes(label)) { if (value.includes(label)) {
// already set // already set
return false return false


+ 3
- 3
frappe/public/js/frappe/ui/field_group.js View File

@@ -69,8 +69,8 @@ frappe.ui.FieldGroup = frappe.ui.form.Layout.extend({
var errors = []; var errors = [];
for(var key in this.fields_dict) { for(var key in this.fields_dict) {
var f = this.fields_dict[key]; var f = this.fields_dict[key];
if(f.get_parsed_value) {
var v = f.get_parsed_value();
if(f.get_value) {
var v = f.get_value();
if(f.df.reqd && is_null(v)) if(f.df.reqd && is_null(v))
errors.push(__(f.df.label)); errors.push(__(f.df.label));


@@ -90,7 +90,7 @@ frappe.ui.FieldGroup = frappe.ui.form.Layout.extend({
}, },
get_value: function(key) { get_value: function(key) {
var f = this.fields_dict[key]; var f = this.fields_dict[key];
return f && (f.get_parsed_value ? f.get_parsed_value() : null);
return f && (f.get_value ? f.get_value() : null);
}, },
set_value: function(key, val){ set_value: function(key, val){
return new Promise(resolve => { return new Promise(resolve => {


+ 8
- 6
frappe/public/js/frappe/ui/filters/filters.js View File

@@ -251,8 +251,12 @@ frappe.ui.Filter = Class.extend({
else if(value==1) value = 'Yes'; else if(value==1) value = 'Yes';
} }


if(condition) this.wrapper.find('.condition').val(condition).change();
if(value!=null) this.field.set_input(value);
if(condition) {
this.wrapper.find('.condition').val(condition).change();
}
if(value!=null) {
this.field.set_value(value);
}
}, },


set_field: function(doctype, fieldname, fieldtype, condition) { set_field: function(doctype, fieldname, fieldtype, condition) {
@@ -294,7 +298,7 @@ frappe.ui.Filter = Class.extend({
// save old text // save old text
var old_text = null; var old_text = null;
if(me.field) { if(me.field) {
old_text = me.field.get_parsed_value();
old_text = me.field.get_value();
} }


var field_area = me.wrapper.find('.filter_field').empty().get(0); var field_area = me.wrapper.find('.filter_field').empty().get(0);
@@ -376,7 +380,7 @@ frappe.ui.Filter = Class.extend({
}, },


get_selected_value: function() { get_selected_value: function() {
var val = this.field.get_parsed_value();
var val = this.field.get_value();


if(typeof val==='string') { if(typeof val==='string') {
val = strip(val); val = strip(val);
@@ -451,8 +455,6 @@ frappe.ui.Filter = Class.extend({
value = {0:"Draft", 1:"Submitted", 2:"Cancelled"}[value] || value; value = {0:"Draft", 1:"Submitted", 2:"Cancelled"}[value] || value;
} else if(this.field.df.original_type==="Check") { } else if(this.field.df.original_type==="Check") {
value = {0:"No", 1:"Yes"}[cint(value)]; value = {0:"No", 1:"Yes"}[cint(value)];
} else if (in_list(["Date", "Datetime"], this.field.df.fieldtype)) {
value = frappe.datetime.str_to_user(value);
} else { } else {
value = this.field.get_value(); value = this.field.get_value();
} }


+ 1
- 1
frappe/public/js/frappe/views/calendar/calendar.js View File

@@ -337,7 +337,7 @@ frappe.views.Calendar = Class.extend({
if(this.filters) { if(this.filters) {
$.each(this.filters, function(i, df) { $.each(this.filters, function(i, df) {
filter_vals[df.fieldname || df.label] = filter_vals[df.fieldname || df.label] =
me.page.fields_dict[df.fieldname || df.label].get_parsed_value();
me.page.fields_dict[df.fieldname || df.label].get_value();
}); });
} }
return filter_vals; return filter_vals;


+ 1
- 1
frappe/public/js/frappe/views/reports/query_report.js View File

@@ -423,7 +423,7 @@ frappe.views.QueryReport = Class.extend({
var filters = {}; var filters = {};
var mandatory_fields = []; var mandatory_fields = [];
$.each(this.filters || [], function(i, f) { $.each(this.filters || [], function(i, f) {
var v = f.get_parsed_value();
var v = f.get_value();
// TODO: hidden fields dont have $input // TODO: hidden fields dont have $input
if(f.df.hidden) v = f.value; if(f.df.hidden) v = f.value;
if(v === '%') v = null; if(v === '%') v = null;


Loading…
Cancel
Save