[英]React-final-form - get state into form values
我想將 map 位置選擇器“插入”到我的一些 forms 中,以將longitude
和latitude
添加到表單值中。
我創建了這個沙箱來展示我遇到的困難。
I can get the map position
into state as the user pans the map, and render the values OK, but I can't get these values into the fields using
<Field
value={position.lat.toFixed(5)}
...
/>
我需要位置選擇器組件Geo.jsx
作為單獨的可重用組件,以便在需要時“插入”到任何 react-final-form Form
。 當用戶想要手動輸入這些值時,我還需要可見和可編輯的latitude
和longitude
輸入。
如果有人能看到我在哪里出錯,將不勝感激。
我通過簡單地將value
更改為defaultValue
來解決這個問題。
在進一步閱讀時,我意識到該value
僅適用於復選框和單選按鈕。
改變
<Field
name="longitude"
label="Longitude"
type="number"
parse={(value) => Number(value)}
component="input"
- value={position.lng.toFixed(5)}
helper="At map center"
/>
至
<Field
name="longitude"
label="Longitude"
type="number"
parse={(value) => Number(value)}
component="input"
+ defaultValue={position.lng.toFixed(5)}
helper="At map center"
/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.