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,
|
||||
}],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
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.validations = {};
|
||||
this.fields = MCF_TypeFactory.buildDefinedObject(this);
|
||||
this.validateValue(definition.value)
|
||||
this.setValue(definition.value)
|
||||
}
|
||||
|
||||
|
@ -201,7 +202,7 @@ class MCF_DefinedObject {
|
|||
return value;
|
||||
}
|
||||
|
||||
setValue(value){
|
||||
validateValue(value){
|
||||
for (let field in this.definition.fields) {
|
||||
if (value[field] === undefined || value === null) {
|
||||
if (this.definition.fields[field].required === true) {
|
||||
|
@ -215,12 +216,14 @@ class MCF_DefinedObject {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (let field in value){
|
||||
if (value[field] === undefined){
|
||||
this.fields[field].value = undefined;
|
||||
setValue(value) {
|
||||
for (let valueKey in value) {
|
||||
if (value[valueKey] === undefined) {
|
||||
this.fields[valueKey].value = undefined;
|
||||
} else {
|
||||
this.fields[field].setValue(value[field]);
|
||||
this.fields[valueKey].setValue(value[valueKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -233,17 +236,20 @@ class MCF_DefinedObject {
|
|||
}
|
||||
|
||||
const fileDefinition = {
|
||||
filename: {TYPE: 'string', required: true},
|
||||
extension: {TYPE: 'string', required: true},
|
||||
path: {TYPE: 'string', required: true},
|
||||
filename: { TYPE: 'string' },
|
||||
extension: { TYPE: 'string' },
|
||||
mimeType: { TYPE: 'string' },
|
||||
path: { TYPE: 'string' },
|
||||
content: { TYPE: 'string' },
|
||||
}
|
||||
|
||||
class MCF_File extends MCF_DefinedObject {
|
||||
constructor(params) {
|
||||
const fields = (params.fields) ? params.fields : {}
|
||||
const value = (params.value) ? params.value : params
|
||||
super({
|
||||
fields: fileDefinition,
|
||||
value: params,
|
||||
fields: {...fileDefinition, ...fields},
|
||||
value: value,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue