Add minor fixes
This commit is contained in:
parent
e4ab9caf94
commit
19554d6848
4 changed files with 76 additions and 70 deletions
|
@ -49,4 +49,4 @@ module.exports = {
|
||||||
'ignoreReadBeforeAssign': true,
|
'ignoreReadBeforeAssign': true,
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
|
|
2
dist/mcf-objects.js
vendored
2
dist/mcf-objects.js
vendored
File diff suppressed because one or more lines are too long
2
dist/mcf-objects.js.map
vendored
2
dist/mcf-objects.js.map
vendored
File diff suppressed because one or more lines are too long
26
src/index.js
26
src/index.js
|
@ -186,6 +186,7 @@ class MCF_DefinedObject {
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
this.validations = {};
|
this.validations = {};
|
||||||
this.fields = MCF_TypeFactory.buildDefinedObject(this);
|
this.fields = MCF_TypeFactory.buildDefinedObject(this);
|
||||||
|
this.validateValue(definition.value)
|
||||||
this.setValue(definition.value)
|
this.setValue(definition.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +202,7 @@ class MCF_DefinedObject {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue(value){
|
validateValue(value){
|
||||||
for (let field in this.definition.fields) {
|
for (let field in this.definition.fields) {
|
||||||
if (value[field] === undefined || value === null) {
|
if (value[field] === undefined || value === null) {
|
||||||
if (this.definition.fields[field].required === true) {
|
if (this.definition.fields[field].required === true) {
|
||||||
|
@ -215,12 +216,14 @@ class MCF_DefinedObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (let field in value){
|
setValue(value) {
|
||||||
if (value[field] === undefined){
|
for (let valueKey in value) {
|
||||||
this.fields[field].value = undefined;
|
if (value[valueKey] === undefined) {
|
||||||
|
this.fields[valueKey].value = undefined;
|
||||||
} else {
|
} else {
|
||||||
this.fields[field].setValue(value[field]);
|
this.fields[valueKey].setValue(value[valueKey]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,17 +236,20 @@ class MCF_DefinedObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileDefinition = {
|
const fileDefinition = {
|
||||||
filename: {TYPE: 'string', required: true},
|
filename: { TYPE: 'string' },
|
||||||
extension: {TYPE: 'string', required: true},
|
extension: { TYPE: 'string' },
|
||||||
path: {TYPE: 'string', required: true},
|
mimeType: { TYPE: 'string' },
|
||||||
|
path: { TYPE: 'string' },
|
||||||
content: { TYPE: 'string' },
|
content: { TYPE: 'string' },
|
||||||
}
|
}
|
||||||
|
|
||||||
class MCF_File extends MCF_DefinedObject {
|
class MCF_File extends MCF_DefinedObject {
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
|
const fields = (params.fields) ? params.fields : {}
|
||||||
|
const value = (params.value) ? params.value : params
|
||||||
super({
|
super({
|
||||||
fields: fileDefinition,
|
fields: {...fileDefinition, ...fields},
|
||||||
value: params,
|
value: value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue