Skip to content

Instantly share code, notes, and snippets.

@elbakerino
Last active May 7, 2020 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbakerino/f183bd9239e66f360176dba5c9170d57 to your computer and use it in GitHub Desktop.
Save elbakerino/f183bd9239e66f360176dba5c9170d57 to your computer and use it in GitHub Desktop.
UI-Schema Custom Validator Scribble
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}/>;
};
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