You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A configuration editor component for JSON data for different products.
It displays a form that is backed by a hookstate with the validation plugin
Displayed fields are dynamically displayed depending on the data. E.G. number fields get a number validation
json for the data is an argument for the editor
Product A has $.daysToDelivery
Product B has $.daysSinceLastAccident
If I switch between those to products and state.set(newData), and afterwards do state.valid(), I get the error for the other product, because the property is missing -> not a number.
I didn't find any way to "reset" the plugin that reruns the onCreate and resets the rules map.
I tried to hookstate(newData, validation()) for the global variable of the state, but get the HOOKSTATE-111
Working example of the problem
functionTest(){const[data,setData]=useState<object>({})return(<div><buttononClick={()=>setData({daysToDelivery: 2})}>ProductA</button><buttononClick={()=>setData({daysSinceLastAccident: 3})}>ProductB</button><TestEditordata={data}/></div>)}exportletglobalState=hookstate<any,Validation>({},validation())functionTestEditor(props: {data: object}){const{ data }=propsconststate=useHookstate(globalState)useEffect(()=>{//globalState = hookstate<any, Validation>(data, validation())state.set(data)},[data])return(<><br/>{state.errors().map((error)=> `${error.path}: ${error.message}`)}<br/><br/>{Object.keys(state.get({noproxy: true})).map((key)=>(<TestNumberFieldpropName={key} number={state.nested(key)}/>))}</>)}functionTestNumberField(props: {propName: string;number: State<any,Validation>}){constvalueState=useHookstate(props.number)valueState.validate((value)=>{constnumber=Number(value)if(isNaN(number))returnfalsereturnNumber.isInteger(number)},"not a number")return(<>{props.propName}<br/><inputvalue={valueState.get()}onChange={(e)=>valueState.set(e.target.value)}/></>)}
The text was updated successfully, but these errors were encountered:
It's an added function that allows for the storeRules to be cleared. Not sure that's the right approach, feels kinda hacky. But it does solve my problem.
Didn't add a unit test for this. But all present tests aren't affected.
Is there another solution that I'm missing? Some way to reset the plugin (rerun onCreate) out of the box that I didn't see?
path.forEach((p)=>{/*if (typeof p === "number") { p = "*" // limitation: support only validation for each element of array }*/result=result&&result[p]})
What's the reason for this limitations? Strictly performance?
I do have non homogenous arrays and this limitation prevents those.
I removed those lines in my copied validation plugin, and it seems to work well.
Hello.
I'm facing issues with the following use case.
A configuration editor component for JSON data for different products.
Product A has $.daysToDelivery
Product B has $.daysSinceLastAccident
If I switch between those to products and
state.set(newData)
, and afterwards dostate.valid()
, I get the error for the other product, because the property is missing -> not a number.I didn't find any way to "reset" the plugin that reruns the
onCreate
and resets the rules map.I tried to
hookstate(newData, validation())
for the global variable of the state, but get the HOOKSTATE-111Working example of the problem
The text was updated successfully, but these errors were encountered: