Skip to content

Commit

Permalink
run form validation
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDevAU committed May 10, 2024
1 parent d2ad668 commit 66317c8
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/@tinacms/scripts/package.json
Expand Up @@ -14,7 +14,7 @@
},
"scripts": {
"build:all": "bin/tina-build build:all",
"watch": "bin/tina-build watch",
"watch": "node bin/tina-build watch",
"build": "yarn tsup src/jest-runner.ts src/css-transform.ts src/index.ts --format cjs"
},
"dependencies": {
Expand Down
Expand Up @@ -233,6 +233,9 @@ export function MediaPicker({
}
}

console.log('CMS: ', cms.media.accept)
console.log('DEFAULT_MEDIA_UPLOAD_TYPES: ', DEFAULT_MEDIA_UPLOAD_TYPES)

const [uploading, setUploading] = useState(false)
const { getRootProps, getInputProps, isDragActive } = useDropzone({
accept: dropzoneAcceptFromString(
Expand Down
1 change: 1 addition & 0 deletions packages/tinacms/src/toolkit/components/media/utils.ts
Expand Up @@ -9,6 +9,7 @@ const supportedFileTypes = [
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'image/*',
'video/*',
]
export const DEFAULT_MEDIA_UPLOAD_TYPES = supportedFileTypes.join(',')

Expand Down
Expand Up @@ -4,7 +4,6 @@ import { InputFieldType, wrapFieldsWithMeta } from '../wrap-field-with-meta'
import { RichEditor } from './plate'
import { EditorContext } from './plate/editor-context'
import type { MdxTemplate } from './plate/types'
import { useRichEditorSave } from '@toolkit/browser-storage/useRichEditorSave'

// TODO: there's an issue where void node values don't get updated if the editor hasn't been focused from another node first.
// https://github.com/udecode/plate/issues/1519#issuecomment-1184933602
Expand Down
Expand Up @@ -13,7 +13,7 @@ import { createInvalidMarkdownPlugin } from './plugins/create-invalid-markdown-p
import { createLinkPlugin } from './plugins/create-link-plugin'
import { uuid } from './plugins/ui/helpers'
import { RichTextType } from '..'
import { useRichEditorSave } from '@toolkit/browser-storage/useRichEditorSave'
import { useRichEditorSave } from '@toolkit/browser-storage/use-rich-editor-save'

export const RichEditor = (props: RichTextType) => {
const [key, setKey] = React.useState(0)
Expand Down
9 changes: 9 additions & 0 deletions packages/tinacms/src/toolkit/forms/form.ts
Expand Up @@ -266,11 +266,16 @@ export class Form<S = any, F extends Field = AnyField> implements Plugin {
this.finalForm.batch(() => {
const activePath = this.finalForm.getState().active

// Validate state here before or after setting values
// ( I think set invalid state is fine )
console.log(this.finalForm)

if (!activePath) {
updateEverything<S>(this.finalForm, values)
} else {
updateSelectively<S>(this.finalForm, values)
}
// this.finalForm.();
})
}

Expand Down Expand Up @@ -572,6 +577,8 @@ export class Form<S = any, F extends Field = AnyField> implements Plugin {
function updateEverything<S>(form: FormApi<any>, values: S) {
Object.entries(values).forEach(([path, value]) => {
form.change(path, value)
// Validate by resetting the field state
form.resetFieldState(path)
})
}

Expand All @@ -590,5 +597,7 @@ function updateSelectively<S>(form: FormApi<any>, values: S, prefix?: string) {
} else if (path !== activePath) {
form.change(path, value)
}
// Validate by resetting the field state
// form.resetFieldState(path)
})
}

0 comments on commit 66317c8

Please sign in to comment.