Which is the best way to handle a form in react?
I'm starting with react, and when I search how handle forms the options that I found are by refs or with states, and events to update state and it is fine but when there are more than 10 fields? I need to get the value of each input to build a JSON because I'm working with an API.
Then which is the best way to handle a form in react? JavaScript? jQuery?
and even if a need to hide and show elements and other things.
You might want to consider using some library to handle your form e.g https://github.com/jaredpalmer/formik
Related
I have created a form in react which has 2 fields. After clicking add button it adds same 2 more fields. Now I want to validate those fields. Can anyone help me please.
Codesandbox link : https://codesandbox.io/s/react-dynamic-form-fields-9fzzh
Your question is a little incomplete. First, tell me which field you want to validate and what you have tried till now. For reference you can check this site:here
There are a couple of ways you can do this. The standard up until recently has been using a large yup schema with conditional validation (using 'when').
I made a library called Fielder specifically for dynamic field-level validation such as in your example. It prevents the need to use a large schema and provide conditions up front.
Check out the second two examples on this page which dynamically add validation criteria as the user progresses through the form.
Check out the Fielder repo and let me know if it works out for you!
I have an input that's used by JS to control submitting two forms with different actions, but only one of them will be submitted and it should include this input.
I can do it with a hidden input using JS to change their values when the original one changes but I'd like to know if there is an HTML5 solution.
Here is my JS code to do it:
$(function(){
$('#originalOne').change(function(){
// check if I should disable a form
$('.hiddenOnes').val($(this).val());
})
});
I think I might be understanding what you are asking, correct me if I'm wrong:
"Is there a way to update the values in one form based on the values in another using HTML5 only (without using JavaScript)?"
Unfortunately, the answer there is NO. You will need to attach event listeners and handle changes using JavaScript. I had previously suggested using a <fieldset> to group the inputs that you wanted to disable independently, but this method does not work for multiple form actions.
In Salesforce, we have a button that creates events with the fields already filled out, but after the item is created I want it to reload the screen in the "Edit" view in case they want to change anything. Any ideas?
Do you need to validate fields values? Maybe it will be easier to do with field validation rules? It can be useful in cases when your data is populated not only from user screens, but also can be created in code (classes/triggers) or via API.
If you know that you exactly should to use JavaScript, you can add standard event attributes to command buttons on your Visualforce page and write JS functions for implementation of your validation logic.
I ended up creating a visualforce page with a controller and a custom button to accomplish what I needed.
Is there a way to use React Native's AlertIOS api to have an alert with multiple textfields? It seems like the prompt function only allows for one.
And if there isn't a way to have multiple textfields, how would I go about adding this functionality to an alert?
Any help would be much appreciated! Thanks!
I assume you would like multiple plain text input fields in your Alert? If so, it is not possible with vanilla React Native. If you look at the source code here and here, you'll see that only plain-text, secure-text or login-password are the available configurations. But if you really want multiple text fields in an Alert box (without considering not-so-great UX) , you could create a native module and do something like this.
I want to acheive this using Angular. I want to use it in a form so that I can retreive my checked values as an array in my controller. I know that I can create custom directives in order to create a custom form control using ngModel. But I think I don't need to create a custom directive for a control like that.
I saw that they are a lot of code that can do this using jQuery but I'm using Angular.
Can anyone give me the best way to acheive this? (HTML, Custom Directive, ...)
Thank you