- Docs on how to create (schema-driven/hook usage) plugins:
- Docs on how add a plugin:
Last active
May 7, 2020 20:43
-
-
Save elbakerino/f183bd9239e66f360176dba5c9170d57 to your computer and use it in GitHub Desktop.
UI-Schema Custom Validator Scribble
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {NextPluginRenderer} from "@ui-schema/ui-schema/EditorPluginStack"; | |
// this is a normal plugin, as we need to access the hook and this is not possible from wihin validatorPlugins | |
const CustomValidator = ({errors, valid, ...props}) => { | |
let {storeKeys} = props; | |
const {store} = useSchemaStore(); | |
// should the internals store be used/compatible for this, maybe the internals store needs another structure | |
const errorForWidget = store.getInternals() ? store.getInternals().getIn(storeKeys.push('server-validation')) : null; | |
if(errorForWidget) { | |
errors.push(errorForWidget);// is the error a single string or also a list? | |
valid = false; | |
} | |
return <NextPluginRenderer {...props} errors={errors} valid={valid}/>; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {createMap, updateInternalValue} from "@ui-schema/ui-schema"; | |
const OnSubmitHandler = ({setStore, setShowValidity})=>{ | |
return <Button onClick={() => { | |
// map the custom validation to the internal store of the widget | |
setStore(updateInternalValue(List(['info']), createMap({'server-validation': 'username-exists'}))) | |
setShowValidity(true) | |
}}>validity</Button> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment