Skip to content

Commit

Permalink
fix(editors): Editors should work with undefined item properties (#540)
Browse files Browse the repository at this point in the history
* fix(editors): Editors should work with undefined item properties
  • Loading branch information
ghiscoding committed Jul 23, 2020
1 parent d9153f9 commit 5c33a48
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 47 deletions.
10 changes: 5 additions & 5 deletions src/app/modules/angular-slickgrid/editors/autoCompleteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class AutoCompleteEditor implements Editor {
}

// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;

// validate the value before applying it (if not valid we'll set an empty string)
const validation = this.validate(newValue);
Expand All @@ -168,11 +168,11 @@ export class AutoCompleteEditor implements Editor {
loadValue(item: any) {
const fieldName = this.columnDef && this.columnDef.field;

// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;
const data = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];

this._currentValue = data;
this._defaultTextValue = typeof data === 'string' ? data : data[this.labelName];
this._$editorElm.val(this._defaultTextValue);
Expand Down
10 changes: 5 additions & 5 deletions src/app/modules/angular-slickgrid/editors/checkboxEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class CheckboxEditor implements Editor {

applyValue(item: any, state: any) {
const fieldName = this.columnDef && this.columnDef.field;
const isComplexObject = fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"

// validate the value before applying it (if not valid we'll set an empty string)
const validation = this.validate(state);
Expand All @@ -102,11 +102,11 @@ export class CheckboxEditor implements Editor {
loadValue(item: any) {
const fieldName = this.columnDef && this.columnDef.field;

// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];

this.originalValue = value;
if (this.originalValue) {
this._$input.prop('checked', true);
Expand Down
10 changes: 5 additions & 5 deletions src/app/modules/angular-slickgrid/editors/dateEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class DateEditor implements Editor {
if (fieldName !== undefined) {
const outputTypeFormat = mapMomentDateFormatWithFieldType((this.columnDef && (this.columnDef.outputType || this.columnDef.type)) || FieldType.dateUtc);
const saveTypeFormat = mapMomentDateFormatWithFieldType((this.columnDef && (this.columnDef.saveOutputType || this.columnDef.outputType || this.columnDef.type)) || FieldType.dateUtc);
const isComplexObject = fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"

// validate the value before applying it (if not valid we'll set an empty string)
const validation = this.validate(state);
Expand Down Expand Up @@ -207,11 +207,11 @@ export class DateEditor implements Editor {
loadValue(item: any) {
const fieldName = this.columnDef && this.columnDef.field;

// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];

this.originalDate = value;
this.flatInstance.setDate(value);
this.show();
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/angular-slickgrid/editors/dualInputEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ export class DualInputEditor implements Editor {
const fieldName = (position === 'leftInput') ? this._leftFieldName : this._rightFieldName;
const originalValuePosition = (position === 'leftInput') ? 'originalLeftValue' : 'originalRightValue';
const inputVarPosition = (position === 'leftInput') ? '_leftInput' : '_rightInput';
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;

if (item && fieldName !== undefined && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;
const itemValue = (isComplexObject) ? getDescendantProperty(item, fieldName) : (item.hasOwnProperty(fieldName) ? item[fieldName] : '');
this[originalValuePosition] = itemValue;
if (this.editorParams[position].type === 'float') {
Expand Down
9 changes: 5 additions & 4 deletions src/app/modules/angular-slickgrid/editors/floatEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class FloatEditor implements Editor {

applyValue(item: any, state: any) {
const fieldName = this.columnDef && this.columnDef.field;
const isComplexObject = fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"

const validation = this.validate(state);
const newValue = (validation && validation.valid) ? state : '';
Expand All @@ -142,11 +142,12 @@ export class FloatEditor implements Editor {
loadValue(item: any) {
const fieldName = this.columnDef && this.columnDef.field;

// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];

this.originalValue = value;
const decPlaces = this.getDecimalPlaces();
if (decPlaces !== null && (this.originalValue || this.originalValue === 0) && (+this.originalValue).toFixed) {
Expand Down
10 changes: 5 additions & 5 deletions src/app/modules/angular-slickgrid/editors/integerEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class IntegerEditor implements Editor {

applyValue(item: any, state: any) {
const fieldName = this.columnDef && this.columnDef.field;
const isComplexObject = fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"

// validate the value before applying it (if not valid we'll set an empty string)
const validation = this.validate(state);
Expand All @@ -116,11 +116,11 @@ export class IntegerEditor implements Editor {
loadValue(item: any) {
const fieldName = this.columnDef && this.columnDef.field;

// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];

this.originalValue = (isNaN(value) || value === null || value === undefined) ? value : `${value}`;
this._$input.val(this.originalValue);
this._$input.select();
Expand Down
10 changes: 5 additions & 5 deletions src/app/modules/angular-slickgrid/editors/longTextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class LongTextEditor implements Editor {

applyValue(item: any, state: any) {
const fieldName = this.columnDef && this.columnDef.field;
const isComplexObject = fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"

// validate the value before applying it (if not valid we'll set an empty string)
const validation = this.validate(state);
Expand All @@ -167,11 +167,11 @@ export class LongTextEditor implements Editor {
loadValue(item: any) {
const fieldName = this.columnDef && this.columnDef.field;

// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];

this.defaultValue = value;
this._$textarea.val(this.defaultValue);
this._$textarea[0].defaultValue = this.defaultValue;
Expand Down
12 changes: 6 additions & 6 deletions src/app/modules/angular-slickgrid/editors/selectEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class SelectEditor implements Editor {
const fieldName = this.columnDef && this.columnDef.field;

// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;
if (isComplexObject && typeof c === 'object') {
return c;
}
Expand Down Expand Up @@ -241,7 +241,7 @@ export class SelectEditor implements Editor {

// is the field a complex object, "address.streetNumber"
const fieldName = this.columnDef && this.columnDef.field;
const isComplexObject = fieldName.indexOf('.') > 0;
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;

if (isComplexObject && typeof itemFound === 'object') {
return itemFound;
Expand Down Expand Up @@ -338,7 +338,7 @@ export class SelectEditor implements Editor {
}

// is the field a complex object, "user.address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;

// validate the value before applying it (if not valid we'll set an empty string)
const validation = this.validate(newValue);
Expand Down Expand Up @@ -371,10 +371,10 @@ export class SelectEditor implements Editor {
loadValue(item: any): void {
const fieldName = this.columnDef && this.columnDef.field;

// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;
if (item && fieldName !== undefined) {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
// when it's a complex object, user could override the object path (where the editable object is located)
// else we use the path provided in the Field Column Definition
const objectPath = this.columnEditor && this.columnEditor.complexObjectPath || fieldName;
Expand Down
10 changes: 5 additions & 5 deletions src/app/modules/angular-slickgrid/editors/sliderEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class SliderEditor implements Editor {

applyValue(item: any, state: any) {
const fieldName = this.columnDef && this.columnDef.field;
const isComplexObject = fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"

const validation = this.validate(state);
const newValue = (validation && validation.valid) ? state : '';
Expand All @@ -137,11 +137,11 @@ export class SliderEditor implements Editor {
loadValue(item: any) {
const fieldName = this.columnDef && this.columnDef.field;

// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;
let value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];

if (value === '' || value === null || value === undefined) {
value = this.defaultValue; // load default value when item doesn't have any value
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/modules/angular-slickgrid/editors/textEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class TextEditor implements Editor {

applyValue(item: any, state: any) {
const fieldName = this.columnDef && this.columnDef.field;
const isComplexObject = fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0; // is the field a complex object, "address.streetNumber"

// validate the value before applying it (if not valid we'll set an empty string)
const validation = this.validate(state);
Expand All @@ -116,11 +116,11 @@ export class TextEditor implements Editor {
loadValue(item: any) {
const fieldName = this.columnDef && this.columnDef.field;

// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];

this.originalValue = value;
this._$input.val(this.originalValue);
this._$input.select();
Expand Down

0 comments on commit 5c33a48

Please sign in to comment.