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

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

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:

&lt;SimpleFormIterator&gt;
    {/* Want a hidden ID field here */}
    &lt;SelectInput label=&quot;Type&quot; source=&quot;type&quot; choices={ ... } /&gt;
    &lt;SelectInput label=&quot;Reason&quot; source=&quot;reason&quot; choices={ ... } /&gt;
    &lt;DateInput label=&quot;Date&quot; source=&quot;date&quot; /&gt;
&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:

&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:

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

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

答案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.

 &lt;TextInput
    source=&quot;id&quot;
    style={{
     position: &#39;absolute&#39;,
     width: 0,
     height: 0,
     zIndex: -100,
     backgroundColor: &#39;#0000&#39;,
    }}
 /&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:

确定