I need to get the value from Form.Select onChange, and also need it to persist from the value property.
Form
<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='[email protected]' 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>
updateInput (MOBX Store)
@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;
}
}
Right now it always returns null. When returning just currentTarget it shows a div element and a inside. Perhaps this is causing the value to be undefined? What is the best way to capture / persist the value of Form.Select onChange?
updateInputis async and you also youtry catchinside. Not quite understand why you need it. Anyway, did you try to useevent.target.valueinstead? Or maybe try invokeevent.persist()awaitinside so there is no reason to mark function asasyncor usetry catch