File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -372,3 +372,53 @@ export const SetValueProgrammaticallyWithNulls = (args) => {
372372 </ RruForm >
373373 ) ;
374374} ;
375+
376+ export const SetValueProgrammaticallyNested = ( args ) => {
377+ const rruFormContext = useRruForm ( ) ;
378+
379+ const initialValues = {
380+ notes : 'old notes' ,
381+ address : {
382+ city : 'Riyadh' ,
383+ street : 'Olya' ,
384+ } ,
385+ hiddenSerial : {
386+ foo : 3 ,
387+ bar : 4 ,
388+ } ,
389+ } ;
390+
391+ const onSubmit = ( form ) => {
392+ action ( 'submitting the form' ) ( form ) ;
393+ } ;
394+
395+ const triggerManualAccess = ( ) => {
396+ action ( 'trigger manual access' ) ( ) ;
397+ action ( 'current form' ) ( rruFormContext . getFieldsValues ( ) ) ;
398+ rruFormContext . setFieldValue ( 'address.street' , 'Tahliah St.' ) ;
399+ rruFormContext . setFieldValue ( 'hiddenSerial' , {
400+ month : 12 ,
401+ sales : 100_550 ,
402+ } ) ;
403+ } ;
404+
405+ return (
406+ < RruForm context = { rruFormContext } initialValues = { initialValues } onSubmit = { onSubmit } >
407+ < RruTextInput name = 'notes' label = 'Notes' />
408+ < RruTextInput name = 'address.city' label = 'City' />
409+ < RruTextInput name = 'address.street' label = 'Street' />
410+
411+ < div style = { { height : 0 , width : 0 , overflow : 'hidden' } } >
412+ < RruTextInput name = 'hiddenSerial' />
413+ </ div >
414+
415+ < button className = 'btn btn-primary mt-4 me-4' onClick = { triggerManualAccess } >
416+ Trigger manual access
417+ </ button >
418+
419+ < button type = 'submit' className = 'btn btn-primary mt-4' >
420+ Submit
421+ </ button >
422+ </ RruForm >
423+ ) ;
424+ } ;
You can’t perform that action at this time.
0 commit comments