[{"data":1,"prerenderedAt":615},["ShallowReactive",2],{"content-\u002Fdocs\u002Fwriting-and-mutating\u002Fset-value":3},{"id":4,"title":5,"body":6,"description":596,"extension":597,"meta":598,"metaRows":599,"navigation":119,"path":610,"seo":611,"source":612,"stem":613,"__hash__":614},"docs\u002Fdocs\u002Fwriting-and-mutating\u002Fset-value.md","setValue patterns",{"type":7,"value":8,"toc":586},"minimark",[9,18,29,32,59,64,68,81,201,208,212,215,336,343,350,363,401,407,418,432,436,446,517,530,534,582],[10,11,13,17],"h1",{"id":12},"setvalue-patterns",[14,15,16],"code",{},"setValue"," patterns",[19,20,21],"blockquote",{},[22,23,24,25,28],"p",{},"The programmatic write surface: three call shapes, a callback option, and the ",[14,26,27],{},"unset"," sentinel for flagging any path blank.",[30,31],"docs-meta-table",{},[22,33,34,35,37,38,41,42,45,46,48,49,52,53,58],{},"Click the four buttons in the demo to exercise every ",[14,36,16],{}," shape: string path, segment tuple, callback, whole-form. The reactive surface (",[14,39,40],{},"values",", ",[14,43,44],{},"fields",", validation) updates the same way it does for directive-driven writes; ",[14,47,16],{}," and ",[14,50,51],{},"v-register"," share the pipeline. The ",[54,55,57],"a",{"href":56},"#three-call-shapes","Three call shapes"," section unpacks each form.",[60,61],"docs-demo",{"label":62,"slug":63},"Set Value Demo","set-value",[65,66,57],"h2",{"id":67},"three-call-shapes",[22,69,70,72,73,76,77,80],{},[14,71,16],{}," accepts whatever shape fits the write site. Each example below assumes a ",[14,74,75],{},"form"," handle from ",[14,78,79],{},"useForm({ schema })",":",[82,83,88],"pre",{"className":84,"code":85,"language":86,"meta":87,"style":87},"language-ts shiki shiki-themes github-light github-dark","const form = useForm({ schema })\n\nform.setValue({ name: 'Ada', age: 30 }) \u002F\u002F whole-form\nform.setValue('profile.email', 'a@b.c') \u002F\u002F dotted path\nform.setValue(['profile', 'email'], 'a@b.c') \u002F\u002F segment tuple\n","ts","",[14,89,90,114,121,149,173],{"__ignoreMap":87},[91,92,95,99,103,106,110],"span",{"class":93,"line":94},"line",1,[91,96,98],{"class":97},"szBVR","const",[91,100,102],{"class":101},"sj4cs"," form",[91,104,105],{"class":97}," =",[91,107,109],{"class":108},"sScJk"," useForm",[91,111,113],{"class":112},"sVt8B","({ schema })\n",[91,115,117],{"class":93,"line":116},2,[91,118,120],{"emptyLinePlaceholder":119},true,"\n",[91,122,124,127,129,132,136,139,142,145],{"class":93,"line":123},3,[91,125,126],{"class":112},"form.",[91,128,16],{"class":108},[91,130,131],{"class":112},"({ name: ",[91,133,135],{"class":134},"sZZnC","'Ada'",[91,137,138],{"class":112},", age: ",[91,140,141],{"class":101},"30",[91,143,144],{"class":112}," }) ",[91,146,148],{"class":147},"sJ8bj","\u002F\u002F whole-form\n",[91,150,152,154,156,159,162,164,167,170],{"class":93,"line":151},4,[91,153,126],{"class":112},[91,155,16],{"class":108},[91,157,158],{"class":112},"(",[91,160,161],{"class":134},"'profile.email'",[91,163,41],{"class":112},[91,165,166],{"class":134},"'a@b.c'",[91,168,169],{"class":112},") ",[91,171,172],{"class":147},"\u002F\u002F dotted path\n",[91,174,176,178,180,183,186,188,191,194,196,198],{"class":93,"line":175},5,[91,177,126],{"class":112},[91,179,16],{"class":108},[91,181,182],{"class":112},"([",[91,184,185],{"class":134},"'profile'",[91,187,41],{"class":112},[91,189,190],{"class":134},"'email'",[91,192,193],{"class":112},"], ",[91,195,166],{"class":134},[91,197,169],{"class":112},[91,199,200],{"class":147},"\u002F\u002F segment tuple\n",[22,202,203,204,207],{},"The dotted-path form is the most ergonomic for plain object schemas. The segment-tuple form sidesteps the dotted-key collision (a schema key that contains a literal ",[14,205,206],{},".",") and gives TypeScript precise typed-tuple inference. The whole-form shape replaces every path at once: useful for hydrating from a server response or applying external state.",[65,209,211],{"id":210},"callback-form","Callback form",[22,213,214],{},"Pass a function to read the current value and return the next:",[82,216,218],{"className":84,"code":217,"language":86,"meta":87,"style":87},"form.setValue('count', (prev) => (prev ?? 0) + 1)\nform.setValue('tags', (prev) => [...prev, 'new-tag'])\nform.setValue(['profile', 'name'], (prev) => prev.trim().toLowerCase())\n",[14,219,220,263,297],{"__ignoreMap":87},[91,221,222,224,226,228,231,234,238,240,243,246,249,252,254,257,260],{"class":93,"line":94},[91,223,126],{"class":112},[91,225,16],{"class":108},[91,227,158],{"class":112},[91,229,230],{"class":134},"'count'",[91,232,233],{"class":112},", (",[91,235,237],{"class":236},"s4XuR","prev",[91,239,169],{"class":112},[91,241,242],{"class":97},"=>",[91,244,245],{"class":112}," (prev ",[91,247,248],{"class":97},"??",[91,250,251],{"class":101}," 0",[91,253,169],{"class":112},[91,255,256],{"class":97},"+",[91,258,259],{"class":101}," 1",[91,261,262],{"class":112},")\n",[91,264,265,267,269,271,274,276,278,280,282,285,288,291,294],{"class":93,"line":116},[91,266,126],{"class":112},[91,268,16],{"class":108},[91,270,158],{"class":112},[91,272,273],{"class":134},"'tags'",[91,275,233],{"class":112},[91,277,237],{"class":236},[91,279,169],{"class":112},[91,281,242],{"class":97},[91,283,284],{"class":112}," [",[91,286,287],{"class":97},"...",[91,289,290],{"class":112},"prev, ",[91,292,293],{"class":134},"'new-tag'",[91,295,296],{"class":112},"])\n",[91,298,299,301,303,305,307,309,312,315,317,319,321,324,327,330,333],{"class":93,"line":123},[91,300,126],{"class":112},[91,302,16],{"class":108},[91,304,182],{"class":112},[91,306,185],{"class":134},[91,308,41],{"class":112},[91,310,311],{"class":134},"'name'",[91,313,314],{"class":112},"], (",[91,316,237],{"class":236},[91,318,169],{"class":112},[91,320,242],{"class":97},[91,322,323],{"class":112}," prev.",[91,325,326],{"class":108},"trim",[91,328,329],{"class":112},"().",[91,331,332],{"class":108},"toLowerCase",[91,334,335],{"class":112},"())\n",[22,337,338,339,342],{},"The callback receives the current value at the path; its return value lands in storage. Equivalent to reading ",[14,340,341],{},"form.values.\u003Cpath>",", computing the next value, and writing it, in one atomic step.",[65,344,346,347],{"id":345},"returns-boolean","Returns ",[14,348,349],{},"boolean",[22,351,352,354,355,358,359,362],{},[14,353,16],{}," returns ",[14,356,357],{},"true"," when the write was accepted, ",[14,360,361],{},"false"," when it was rejected by the slim-type gate (value didn't match the leaf's accept set). Reach for the return value when a downstream action depends on the write succeeding:",[82,364,366],{"className":84,"code":365,"language":86,"meta":87,"style":87},"if (form.setValue('age', 21)) {\n  \u002F* proceed *\u002F\n}\n",[14,367,368,391,396],{"__ignoreMap":87},[91,369,370,373,376,378,380,383,385,388],{"class":93,"line":94},[91,371,372],{"class":97},"if",[91,374,375],{"class":112}," (form.",[91,377,16],{"class":108},[91,379,158],{"class":112},[91,381,382],{"class":134},"'age'",[91,384,41],{"class":112},[91,386,387],{"class":101},"21",[91,389,390],{"class":112},")) {\n",[91,392,393],{"class":93,"line":116},[91,394,395],{"class":147},"  \u002F* proceed *\u002F\n",[91,397,398],{"class":93,"line":123},[91,399,400],{"class":112},"}\n",[65,402,404,405],{"id":403},"same-pipeline-as-v-register","Same pipeline as ",[14,406,51],{},[22,408,409,410,412,413,41,415,417],{},"Every ",[14,411,16],{}," call flows through the same write pipeline as the directive: slim-type gating, dirty \u002F touched tracking, persistence, multi-tab sync, history. The reactive surface (",[14,414,40],{},[14,416,44],{},", validation) reacts identically. No \"programmatic writes are second-class\" carve-out.",[22,419,420,421,423,424,428,429,431],{},"The one difference: ",[14,422,16],{}," writes are ",[425,426,427],"strong",{},"never coerced",". Coercion is for user-typed DOM strings; values you pass to ",[14,430,16],{}," are already typed at the call site (TypeScript checks it), so coercion would be a no-op at best and a footgun at worst.",[65,433,435],{"id":434},"flagging-a-path-blank","Flagging a path blank",[22,437,438,439,441,442,445],{},"To flag a path as displayed-empty, pass the ",[14,440,27],{}," sentinel. The runtime writes the schema's slim value at that path and joins the path to ",[14,443,444],{},"form.blankPaths"," so the bound input renders empty.",[82,447,449],{"className":84,"code":448,"language":86,"meta":87,"style":87},"import { unset } from 'attaform\u002Fzod'\n\nform.setValue('middleName', unset) \u002F\u002F storage holds '', form.blankPaths has 'middleName'\nform.setValue('profile', unset) \u002F\u002F recursive, marks every primitive descendant\nform.setValue('cargo', unset) \u002F\u002F DU stub, writes { kind: '' } with no variant body\n",[14,450,451,465,469,486,501],{"__ignoreMap":87},[91,452,453,456,459,462],{"class":93,"line":94},[91,454,455],{"class":97},"import",[91,457,458],{"class":112}," { unset } ",[91,460,461],{"class":97},"from",[91,463,464],{"class":134}," 'attaform\u002Fzod'\n",[91,466,467],{"class":93,"line":116},[91,468,120],{"emptyLinePlaceholder":119},[91,470,471,473,475,477,480,483],{"class":93,"line":123},[91,472,126],{"class":112},[91,474,16],{"class":108},[91,476,158],{"class":112},[91,478,479],{"class":134},"'middleName'",[91,481,482],{"class":112},", unset) ",[91,484,485],{"class":147},"\u002F\u002F storage holds '', form.blankPaths has 'middleName'\n",[91,487,488,490,492,494,496,498],{"class":93,"line":151},[91,489,126],{"class":112},[91,491,16],{"class":108},[91,493,158],{"class":112},[91,495,185],{"class":134},[91,497,482],{"class":112},[91,499,500],{"class":147},"\u002F\u002F recursive, marks every primitive descendant\n",[91,502,503,505,507,509,512,514],{"class":93,"line":175},[91,504,126],{"class":112},[91,506,16],{"class":108},[91,508,158],{"class":112},[91,510,511],{"class":134},"'cargo'",[91,513,482],{"class":112},[91,515,516],{"class":147},"\u002F\u002F DU stub, writes { kind: '' } with no variant body\n",[22,518,519,521,522,529],{},[14,520,27],{}," works at every path the consumer can address: primitive leaves, containers, arrays, tuples, records, discriminated unions, wrappers, and the root. See ",[54,523,525,526,528],{"href":524},"\u002Fdocs\u002Fwriting-and-mutating\u002Funset","the ",[14,527,27],{}," page"," for the full contract.",[65,531,533],{"id":532},"where-to-next","Where to next",[535,536,537,551,560,567],"ul",{},[538,539,540,550],"li",{},[54,541,543,546,547],{"href":542},"\u002Fdocs\u002Fwriting-and-mutating\u002Freset",[14,544,545],{},"reset"," & ",[14,548,549],{},"resetField",": restore defaults instead of just writing.",[538,552,553,559],{},[54,554,556],{"href":555},"\u002Fdocs\u002Fwriting-and-mutating\u002Fclear",[14,557,558],{},"clear",": write blank values without going through defaults.",[538,561,562,566],{},[54,563,565],{"href":564},"\u002Fdocs\u002Fwriting-and-mutating\u002Ffield-arrays","Field-array mutations",": append, insert, remove, swap, move, replace, prepend.",[538,568,569,573,574,41,577,579,580,206],{},[54,570,571],{"href":524},[14,572,27],{},": the blank-anywhere sentinel for ",[14,575,576],{},"defaultValues",[14,578,16],{},", and ",[14,581,545],{},[583,584,585],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}",{"title":87,"searchDepth":116,"depth":116,"links":587},[588,589,590,592,594,595],{"id":67,"depth":116,"text":57},{"id":210,"depth":116,"text":211},{"id":345,"depth":116,"text":591},"Returns boolean",{"id":403,"depth":116,"text":593},"Same pipeline as v-register",{"id":434,"depth":116,"text":435},{"id":532,"depth":116,"text":533},"form.setValue is the programmatic write surface, set the whole form, one path, or a segment-tuple, with values or a callback. Every directive write flows through the same pipeline.","md",{},[600,603,606,608],{"label":601,"value":602},"Category","Return method",{"label":604,"value":605,"kind":14},"Signatures","setValue(value) · setValue(path, value) · setValue(segments, value)",{"label":211,"value":607,"kind":14},"(prev, ctx) => next",{"label":609,"value":349,"kind":14},"Returns","\u002Fdocs\u002Fwriting-and-mutating\u002Fset-value",{"title":5,"description":596},null,"docs\u002Fwriting-and-mutating\u002Fset-value","Fe_h9lAUJLFG9MhfZx8hHW1YOkc_n3u9DfXXm0v5Xwc",1780949759681]