英文:
Create hidden ID field using React-Admin in React Native
问题
I am trying to use the SimpleFormIterator
in the React-Admin module to create a list of children records from the parent record edit form.
So I've setup a SimpleFormIterator
component with the details of the child record, however, this doesn't return back an ID, so when I submit the form no ID for the child is maintained. This can be seen below:
<SimpleFormIterator>
{/* Want a hidden ID field here */}
<SelectInput label="Type" source="type" choices={ ... } />
<SelectInput label="Reason" source="reason" choices={ ... } />
<DateInput label="Date" source="date" />
</SimpleFormIterator>
General HTML code would suggest I need a hidden input to store the ID, however, I can't work out a way to do this using React-Admin.
I've tried adding a TextInput
component into the SimpleFormIterator
, such as:
<TextInput source="id" hidden />
But the input is not hidden for some reason, it is shown to the client.
I've also thought to use the key
property of the SimpleFormIterator
but I don't know how to access the current list of elements to directly access the ID value.
What am I missing, why is the field showing, or is there another way to maintain the ID against that child record?
英文:
I am trying to use the SimpleFormIterator
in the React-Admin module to create a list of children records from the parent record edit form.
So I've setup a SimpleFormIterator
component with the details of the child record, however, this doesn't return back an ID, so when I submit the form no ID for the child is maintained. This can be seen below:
<SimpleFormIterator>
{/* Want a hidden ID field here */}
<SelectInput label="Type" source="type" choices={ ... } />
<SelectInput label="Reason" source="reason" choices={ ... } />
<DateInput label="Date" source="date" />
</SimpleFormIterator>
General HTML code would suggest I need a hidden input to store the ID, however, I can't work out a way to do this using React-Admin.
I've tried adding a TextInput
component into the SimpleFormIterator
, such as:
<TextInput source="id" hidden />
But the input is not hidden for some reason, it is shown to the client.
I've also thought to use the key
property of the SimpleFormIterator
but I don't know how to access the current list of elements to directly access the ID value.
What am I missing, why is the field showing, or is there another way to maintain the ID against that child record?
答案1
得分: 2
但你可以以以下方式隐藏你的TextInput:
<TextInput source="id" style={{display:'none'}}/>
英文:
I do not understand perfectly what you want to do.
But you can hide your TextInput the following way:
<TextInput source="id" style={{display:'none'}}/>
答案2
得分: 0
在React Native中创建一个隐藏字段,您可以使用以下代码:
<TextInput
source="id"
style={{
position: 'absolute',
width: 0,
height: 0,
zIndex: -100,
backgroundColor: '#0000',
}}
/>
英文:
to create a hidden field in react-native you can use the folloing code.
<TextInput
source="id"
style={{
position: 'absolute',
width: 0,
height: 0,
zIndex: -100,
backgroundColor: '#0000',
}}
/>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论