Skip to content

Commit

Permalink
Fix bug with ControlDate
Browse files Browse the repository at this point in the history
  • Loading branch information
UmSenhorQualquer committed Apr 4, 2019
1 parent 173a67e commit c278257
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 3 additions & 4 deletions pyforms_web/controls/control_date.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from datetime import date
from pyforms_web.controls.control_base import ControlBase
import simplejson

Expand All @@ -20,9 +21,7 @@ def value(self, value):

if value is not None and not isinstance(value, datetime.date):
try:
value = parse_datetime(value)
value = timezone.localtime(value)
value = value.date()
value = datetime.datetime.strptime(value, '%Y%m%d')
except:
raise Exception('The value is not a valid date')

Expand All @@ -35,7 +34,7 @@ def value(self, value):

def serialize(self):
data = ControlBase.serialize(self)

if self.value:
data.update({'value': self.value.isoformat()} )
return data
1 change: 1 addition & 0 deletions pyforms_web/web/static/pyforms.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pyforms_web/web/static/pyformsjs/ControlDate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class ControlDate extends ControlBase{

get_value(){
//if(this.jquery().length==0) return this.properties.value;
return this.jquery().datepicker('getDate');
};

Expand All @@ -22,6 +21,12 @@ class ControlDate extends ControlBase{
this.jquery().val('');
}

serialize(){
var d = this.get_value();
this.properties.value = d.getFullYear()+("0"+(d.getMonth()+1)).slice(-2)+ ("0" + d.getDate()).slice(-2);
return this.properties;
}

////////////////////////////////////////////////////////////////////////////////

init_control(){
Expand Down

0 comments on commit c278257

Please sign in to comment.