Skip to content

Commit

Permalink
fix(editors): fix serialization/deserilization in editors
Browse files Browse the repository at this point in the history
Merge pull request #58 from ghiscoding/fix/editor_serialization
  • Loading branch information
jmzagorski committed May 18, 2018
2 parents 2112768 + 7bc8baf commit f3610d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions aurelia-slickgrid/src/aurelia-slickgrid/editors/dateEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,26 @@ export class DateEditor implements Editor {

loadValue(item: any) {
this.defaultDate = item[this.args.column.field];
this.flatInstance.setDate(item[this.args.column.field]);
}

serializeValue() {
const domValue: string = this.$input.val();

if (!domValue) return '';

const outputFormat = mapMomentDateFormatWithFieldType(this.args.column.type || FieldType.dateIso);
const value = moment(this.defaultDate).format(outputFormat);
const value = moment(domValue).format(outputFormat);

return value;
}

applyValue(item: any, state: any) {
item[this.args.column.field] = state;
if (!state) return;

const outputFormat = mapMomentDateFormatWithFieldType(this.args.column.type || FieldType.dateIso);

item[this.args.column.field] = moment(state, outputFormat).toDate();
}

isValueChanged() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export class SingleSelectEditor implements Editor {

loadValue(item: any): void {
// convert to string because that is how the DOM will return these values
this.defaultValue = item[this.columnDef.field].toString();
// make sure the prop exists first
this.defaultValue = item[this.columnDef.field] && item[this.columnDef.field].toString();

this.$editorElm.find('option').each((i: number, $e: any) => {
if (this.defaultValue === $e.value) {
Expand Down

0 comments on commit f3610d7

Please sign in to comment.