diff options
Diffstat (limited to 'src/client/views/collections/CollectionSchemaView.tsx')
| -rw-r--r-- | src/client/views/collections/CollectionSchemaView.tsx | 24 | 
1 files changed, 16 insertions, 8 deletions
| diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx index 0ff6c3b40..b10aaba98 100644 --- a/src/client/views/collections/CollectionSchemaView.tsx +++ b/src/client/views/collections/CollectionSchemaView.tsx @@ -86,12 +86,10 @@ export class CollectionSchemaView extends CollectionViewBase {          )          let reference = React.createRef<HTMLDivElement>();          let onItemDown = setupDrag(reference, () => props.doc, (containingCollection: CollectionView) => this.props.removeDocument(props.doc)); -        let applyToDoc = (doc: Document, value: string) => { -            let script = CompileScript(value, { this: doc }, true); -            if (!script.compiled) { -                return false; -            } -            let field = script(); +        let applyToDoc = (doc: Document, run: (args?: { [name: string]: any }) => any) => { +            const res = run({ this: doc }); +            if (!res.success) return false; +            const field = res.result;              if (field instanceof Field) {                  doc.Set(props.fieldKey, field);                  return true; @@ -118,12 +116,22 @@ export class CollectionSchemaView extends CollectionViewBase {                          return field || "";                      }}                      SetValue={(value: string) => { -                        return applyToDoc(props.doc, value); +                        let script = CompileScript(value, { addReturn: true, params: { this: "Document" } }); +                        if (!script.compiled) { +                            return false; +                        } +                        return applyToDoc(props.doc, script.run);                      }}                      OnFillDown={(value: string) => { +                        let script = CompileScript(value, { addReturn: true, params: { this: "Document" } }); +                        if (!script.compiled) { +                            return; +                        } +                        const run = script.run; +                        //TODO This should be able to be refactored to compile the script once                          this.props.Document.GetTAsync<ListField<Document>>(this.props.fieldKey, ListField).then((val) => {                              if (val) { -                                val.Data.forEach(doc => applyToDoc(doc, value)); +                                val.Data.forEach(doc => applyToDoc(doc, run));                              }                          })                      }}> | 
