[fix] grid.js and control.js. cleanup datepicker formatting and parsing

This commit is contained in:
Rushabh Mehta 2017-06-19 15:10:59 +05:30
parent 19736308b6
commit 5e581a1b69
3 changed files with 19 additions and 15 deletions

View file

@ -464,10 +464,13 @@ frappe.ui.form.ControlData = frappe.ui.form.ControlInput.extend({
set_input: function(value) {
this.last_value = this.value;
this.value = value;
this.$input && this.$input.val(this.format_for_input(value));
this.set_formatted_input(value);
this.set_disp_area();
this.set_mandatory && this.set_mandatory(value);
},
set_formatted_input: function(value) {
this.$input && this.$input.val(this.format_for_input(value));
},
get_value: function() {
return this.$input ? this.$input.val() : undefined;
},
@ -631,10 +634,9 @@ frappe.ui.form.ControlDate = frappe.ui.form.ControlData.extend({
this.set_datepicker();
this.set_t_for_today();
},
set_input: function(value) {
this._super(value);
set_formatted_input: function(value) {
if(value
&& ((this.last_value && this.last_value !== this.value)
&& ((this.last_value && this.last_value !== value)
|| (!this.datepicker.selectedDates.length))) {
this.datepicker.selectDate(frappe.datetime.str_to_obj(value));
}
@ -651,8 +653,6 @@ frappe.ui.form.ControlDate = frappe.ui.form.ControlData.extend({
todayButton: new Date(),
dateFormat: (frappe.boot.sysdefaults.date_format || 'yyyy-mm-dd'),
onSelect: function(dateStr) {
if(me.setting_date_flag) return;
me.set_value(me.get_value());
me.$input.trigger('change');
},
onShow: function() {
@ -668,7 +668,16 @@ frappe.ui.form.ControlDate = frappe.ui.form.ControlData.extend({
var me = this;
this.$input.on("keydown", function(e) {
if(e.which===84) { // 84 === t
me.set_value(frappe.datetime.str_to_user(frappe.datetime.nowdate()));
if(me.df.fieldtype=='Date') {
me.set_value(frappe.datetime.str_to_user(
frappe.datetime.nowdate()));
} if(me.df.fieldtype=='Datetime') {
me.set_value(frappe.datetime.str_to_user(
frappe.datetime.now_datetime()));
} if(me.df.fieldtype=='Time') {
me.set_value(frappe.datetime.str_to_user(
frappe.datetime.now_time()));
}
return false;
}
});
@ -704,7 +713,7 @@ frappe.ui.form.ControlTime = frappe.ui.form.ControlData.extend({
onlyTimepicker: true,
timeFormat: "hh:ii:ss",
onSelect: function(dateObj) {
me.set_value(dateObj);
me.$input.trigger('change');
},
onShow: function() {
$('.datepicker--button:visible').text(__('Now'));

View file

@ -981,11 +981,6 @@ frappe.ui.form.GridRow = Class.extend({
if (this.columns_list && this.columns_list.slice(-1)[0]===column) {
field.$input.attr('data-last-input', 1);
}
field.$input.on('change', function(e) {
field.$input.trigger('blur');
me.doc[df.fieldname] = field.get_value();
me.grid.set_value(df.fieldname, me.doc[df.fieldname], me.doc);
});
}
this.set_arrow_keys(field);

View file

@ -12,10 +12,10 @@
<button type="reset"
class="grid-add-multiple-rows btn btn-xs btn-default hide"
style="margin-right: 10px;">
{%= __("Add multiple rows") %}</a>
{%= __("Add Multiple") %}</a>
<!-- hack to allow firefox include this in tabs -->
<button type="reset" class="btn btn-xs btn-default grid-add-row">
{%= __("Add new row") %}</button>
{%= __("Add Row") %}</button>
</div>
<div class="col-sm-6 text-right">
<a href="#" class="grid-download btn btn-xs btn-default hide"