使用React-Admin在React Native中创建隐藏的ID字段。

huangapple go评论91阅读模式
英文:

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:

  1. <SimpleFormIterator>
  2. {/* Want a hidden ID field here */}
  3. <SelectInput label="Type" source="type" choices={ ... } />
  4. <SelectInput label="Reason" source="reason" choices={ ... } />
  5. <DateInput label="Date" source="date" />
  6. </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:

  1. <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:

  1. &lt;SimpleFormIterator&gt;
  2. {/* Want a hidden ID field here */}
  3. &lt;SelectInput label=&quot;Type&quot; source=&quot;type&quot; choices={ ... } /&gt;
  4. &lt;SelectInput label=&quot;Reason&quot; source=&quot;reason&quot; choices={ ... } /&gt;
  5. &lt;DateInput label=&quot;Date&quot; source=&quot;date&quot; /&gt;
  6. &lt;/SimpleFormIterator&gt;

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:

  1. &lt;TextInput source=&quot;id&quot; hidden /&gt;

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:

  1. <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:

  1. &lt;TextInput source=&quot;id&quot; style={{display:&#39;none&#39;}}/&gt;

答案2

得分: 0

在React Native中创建一个隐藏字段,您可以使用以下代码:

  1. <TextInput
  2. source="id"
  3. style={{
  4. position: 'absolute',
  5. width: 0,
  6. height: 0,
  7. zIndex: -100,
  8. backgroundColor: '#0000',
  9. }}
  10. />
英文:

to create a hidden field in react-native you can use the folloing code.

  1. &lt;TextInput
  2. source=&quot;id&quot;
  3. style={{
  4. position: &#39;absolute&#39;,
  5. width: 0,
  6. height: 0,
  7. zIndex: -100,
  8. backgroundColor: &#39;#0000&#39;,
  9. }}
  10. /&gt;

huangapple
  • 本文由 发表于 2023年7月6日 21:44:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629510.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定