admin管理员组文章数量:1023282
I want to create a TextField like the one in the image below, where users can manually type a formula (e.g., Basic Fuel + Basic Kurs, (Basic Fuel + Basic Kurs)/Basic Fuel), and a dropdown appears showing available variables (e.g., Basic Fuel, Basic Kurs, etc.) as the user types. How can I implement this in React?
The dropdown should behave as follows:
- When a user starts typing, it shows suggestions based on the available variables (like an autocomplete).
- The user can select a variable from the dropdown to insert it into the formula.
- The TextField should allow free typing for operators like
+
,-
,*
, etc.
I have tried to implement the Select component from ant design with "tags" mode, but I am confused, how can the user write the operators manually.
I want to create a TextField like the one in the image below, where users can manually type a formula (e.g., Basic Fuel + Basic Kurs, (Basic Fuel + Basic Kurs)/Basic Fuel), and a dropdown appears showing available variables (e.g., Basic Fuel, Basic Kurs, etc.) as the user types. How can I implement this in React?
The dropdown should behave as follows:
- When a user starts typing, it shows suggestions based on the available variables (like an autocomplete).
- The user can select a variable from the dropdown to insert it into the formula.
- The TextField should allow free typing for operators like
+
,-
,*
, etc.
I have tried to implement the Select component from ant design with "tags" mode, but I am confused, how can the user write the operators manually.
Share Improve this question edited Nov 19, 2024 at 8:18 rzickler 7731 gold badge6 silver badges21 bronze badges asked Nov 19, 2024 at 6:58 NizarNizar 35 bronze badges 5- This isn't nearly enough info here. Also it's expected you at least try something yourself and we can help iron out specific issues you're facing. How are they typing the formula? What variables can they use, any? Or from a set list? You say "a TextField like the one in the image", but it seems the image shows a dropdown box. We're going to need more info with an attempt of a basic example and a clear description of specific issues you're facing – Jayce444 Commented Nov 19, 2024 at 7:07
- Hi @Jayce444, Thank you for your feedback! I’ve updated my question with a clearer description, a basic example of what I’ve tried so far, and the specific issues I’m facing. I hope the revised version is now clear and provides enough context to help address the problem. – Nizar Commented Nov 19, 2024 at 7:23
- okay so to be clear, you're talking about typing into a dropdown, which isn't possible. A text field and a dropdown are 2 separate things. Do you mean a text field that when you type into it, suggestions appear below, like a select input? Do you have a real world example of what you're after we can look at? – Jayce444 Commented Nov 19, 2024 at 9:37
- Yes, that's exactly what I meant. I struggled to explain it clearly. I found a real-world example that closely matches my case here: stackoverflow/a/22173698/10501598. Do you have any other suggestions ? – Nizar Commented Nov 19, 2024 at 14:51
- Hi @Jayce444, I’ve found a solution to this issue. If you have suggestions for improvement, I would really appreciate it. Thanks – Nizar Commented Nov 20, 2024 at 7:09
1 Answer
Reset to default 0I’ve found a solution to this issue, but I want to make sure it’s the optimal approach. If anyone has suggestions for improvement, I would really appreciate it.
My solution: https://codesandbox.io/p/sandbox/select-custom-formula-qpp7ds
I want to create a TextField like the one in the image below, where users can manually type a formula (e.g., Basic Fuel + Basic Kurs, (Basic Fuel + Basic Kurs)/Basic Fuel), and a dropdown appears showing available variables (e.g., Basic Fuel, Basic Kurs, etc.) as the user types. How can I implement this in React?
The dropdown should behave as follows:
- When a user starts typing, it shows suggestions based on the available variables (like an autocomplete).
- The user can select a variable from the dropdown to insert it into the formula.
- The TextField should allow free typing for operators like
+
,-
,*
, etc.
I have tried to implement the Select component from ant design with "tags" mode, but I am confused, how can the user write the operators manually.
I want to create a TextField like the one in the image below, where users can manually type a formula (e.g., Basic Fuel + Basic Kurs, (Basic Fuel + Basic Kurs)/Basic Fuel), and a dropdown appears showing available variables (e.g., Basic Fuel, Basic Kurs, etc.) as the user types. How can I implement this in React?
The dropdown should behave as follows:
- When a user starts typing, it shows suggestions based on the available variables (like an autocomplete).
- The user can select a variable from the dropdown to insert it into the formula.
- The TextField should allow free typing for operators like
+
,-
,*
, etc.
I have tried to implement the Select component from ant design with "tags" mode, but I am confused, how can the user write the operators manually.
Share Improve this question edited Nov 19, 2024 at 8:18 rzickler 7731 gold badge6 silver badges21 bronze badges asked Nov 19, 2024 at 6:58 NizarNizar 35 bronze badges 5- This isn't nearly enough info here. Also it's expected you at least try something yourself and we can help iron out specific issues you're facing. How are they typing the formula? What variables can they use, any? Or from a set list? You say "a TextField like the one in the image", but it seems the image shows a dropdown box. We're going to need more info with an attempt of a basic example and a clear description of specific issues you're facing – Jayce444 Commented Nov 19, 2024 at 7:07
- Hi @Jayce444, Thank you for your feedback! I’ve updated my question with a clearer description, a basic example of what I’ve tried so far, and the specific issues I’m facing. I hope the revised version is now clear and provides enough context to help address the problem. – Nizar Commented Nov 19, 2024 at 7:23
- okay so to be clear, you're talking about typing into a dropdown, which isn't possible. A text field and a dropdown are 2 separate things. Do you mean a text field that when you type into it, suggestions appear below, like a select input? Do you have a real world example of what you're after we can look at? – Jayce444 Commented Nov 19, 2024 at 9:37
- Yes, that's exactly what I meant. I struggled to explain it clearly. I found a real-world example that closely matches my case here: stackoverflow/a/22173698/10501598. Do you have any other suggestions ? – Nizar Commented Nov 19, 2024 at 14:51
- Hi @Jayce444, I’ve found a solution to this issue. If you have suggestions for improvement, I would really appreciate it. Thanks – Nizar Commented Nov 20, 2024 at 7:09
1 Answer
Reset to default 0I’ve found a solution to this issue, but I want to make sure it’s the optimal approach. If anyone has suggestions for improvement, I would really appreciate it.
My solution: https://codesandbox.io/p/sandbox/select-custom-formula-qpp7ds
版权声明:本文标题:reactjs - How to create a TextField for manual formula input with a variable dropdown in React? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745579434a2157221.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论