gpt4 book ai didi

reactjs - Form.Select 值 onChange 语义 UI React

转载 作者:行者123 更新时间:2023-12-04 09:36:27 25 4
gpt4 key购买 nike

我需要从 Form.Select onChange 中获取值,并且还需要它从 value 属性中持久化。

表格

            <Form onSubmit={submitSSOLink}>
<Form.Group widths='equal'>
<Form.Input required={true} onChange={(e) => updateInput(e,"name")} fluid label='Name' placeholder='Gitlab' value={name} />
<Form.Input required={true} onChange={(e) => updateInput(e,"link")} fluid label='Link Url' placeholder='https://www.gitlab.com' type="url" value={link} />
</Form.Group>
<Form.Group>
<Form.Select
fluid
label='Category'
placeholder='Category'
options={options}
onChange={(e:any) => updateInput(e,"category")}
required={true}
value={category}
/>
</Form.Group>
<Form.Group widths='equal'>
<Form.Input required={true} onChange={(e) => updateInput(e, "owner")} fluid label='Owner' placeholder='Ian Malcolm' value={owner} />
<Form.Input required={true} onChange={(e) => updateInput(e,"ownerEmail")} fluid label='Owner Email' placeholder='Ian.Malcolm@JP.com' type="email" value={ownerEmail} />
</Form.Group>
<Form.TextArea required={true} onChange={(e) => updateInput(e,"description")} fluid label='Description' placeholder='Fantastic resource' type="text" value={description} />
<Button type='submit'>Submit</Button>
</Form>

更新输入(MOBX 商店)

@action updateInput = async (e:any, fieldName:string) => {
this.loadingStatus = true;
console.log(e.currentTarget)
try {
runInAction('updating field value', () => {
switch(fieldName) {
case "name":
this.name = e.currentTarget.value;
break;
case "link":
this.link = e.currentTarget.value;
break;
case "category":
this.category = e.currentTarget.value;
break;
case "owner":
this.owner = e.currentTarget.value;
break;
case "ownerEmail":
this.ownerEmail = e.currentTarget.value;
break;
case "description":
this.description = e.currentTarget.value;
break;
}
})
console.log(e.currentTarget.getAttribute('value'))
} catch (error) {
console.log(error);
this.loadingStatus = false;
}
}

现在它总是返回 null。当只返回 currentTarget 时,它显示一个 div 元素和一个内部。也许这导致值未定义?捕获/保留 Form.Select onChange 值的最佳方法是什么?

最佳答案

我最终在 GitHub 上偶然发现了一个帮助我解决问题的问题。只是把它放在这里以防有人遇到同样的问题。

https://github.com/Semantic-Org/Semantic-UI-React/issues/798

<Form.Select
fluid
label='Category'
placeholder='Category'
options={options}
onChange={(e:any, {value}) => updateCategory(e, value?.toString())}
required={true}
value={category}
/>

在我的商店中创建了另一个 Action

@action updateCategory = async (e:any, value: string|undefined) => {
this.loadingStatus = true;
try {
runInAction('updating category', () => {
if (value != undefined) {
this.category = value;
}
console.log(value);
})
} catch (error) {
console.log(error)
this.loadingStatus = false;
}
}

关于reactjs - Form.Select 值 onChange 语义 UI React,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62559904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com