Edit Redux Form with FieldArray - redux-form

I have create a Redux Form with FieldArray as mentioned in its example, where you can add multiple Member and Hobbies and Submit the Form.
https://redux-form.com/8.1.0/examples/fieldarrays/
Can we Edit the same Form by accessing the form from database? The Edit form should display all the fields and Button I have created before ?
Please advise how different sub-component(which is created using FieldArray ) will populate the values.
Thank you

You can reuse the same form for editing.
A field array is mapped into redux as array of objects or array of strings (depending how you do the fields.push).
If you provide that exact format to the initialValues prop when you mount the redux form, it will populate the FieldArray accordingly

Related

How can i get data from database for dropdownlist in Form in Laravel using laravel collectives?

I have used usual dropdown list and it's not worked,
when i click the submit button for all the data in the form except drop down value were sent to database.how can i fix it??
Your <select> is missing a name="foo" attribute.
A form will only submit elements with a name as part of the request.

Don't render part of Model form Django

I take some form choices from database by using ModelChoiceField in the form.
But i don't want to render select in form template if ModelChoiceField return empty QuerySet. How to do this?

Populate Select2 multiple select box with user selected data after Laravel 4 redirect

I have a Select2 multiple select box on a form, for users to select the countries they have previously visited. I'm using Laravel 4 and when the form is submitted, it then validates all form fields and redirects back to the form if any validation errors have occurred - repopulating the form with the users previous input ( using Input::old('???') ).
My questions is how can I reapply the users previous selections to the Select2 multiple select box, using the data stored in Input::old('countries[]') ?
Where in my JavaScript code would I add the ID's of the users previous selections?
$(document).ready(function() {
$('#inputCountries').select2(); // How do I add selections?
});
I think you just need to provide the array of IDs of countries as an argument of selected items. Might need to use one of array_keys to get just the IDs passed into the selected items array.

Symfony2 form dynamic select entity

I searched for a while, but i didn't find anything.
I want to create a dynamic select with another select. Example :
in my form i have two field (category & subcategory) linked to an entity, when i select an item in category drop-down the item in subcategory will change.
So ok i found i can manage with a event listener.
$builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event){
$form = $event->getForm();
$data = $event->getData();
var_dump($data->getCategory());
});
Ok, i can get the selected category and after load the subcategory, but how i can call this with ajax ?
Hope you have any example...
The response is not so simple... Basically, if you want to build a form according to initial & submitted value, you need to attach an event listener to the PRE_SET_DATA & PRE_SUBMIT event. When the form is initialized, the PRE_SET_DATA event is fired. Here, you will receive your object as data in the form event or null if you don't provide one (Don't forget to handle this case). With this first part, you will be able to build your form dynamically according to your initial data.
Then, when you will handle your form, the PRE_SUBMIT event will be fired if the form is submitted. In this event, you will reveive a flat array wilt all the submitted datas. According to this array, you can rebuild your form according to the submitted datas. The main issue here is the array is an array & not your model object. Meaning you will not have a category object but his view representation (his ID)...
Hope it helps!

codeigniter form prepopulation

Is there a method to prepopulate a certain field in a form using data from the previous page using codeigniter.
I have a page with input fields that are filled out, if the user presses a "add" button they are given a new form with similar fields. I want those fields to be populated from data received by the previous page.
You can use CI's form helper function set_value() which uses the $_POST and may save you some code testing if the $_POST value is empty because you can specify a default value if not set. Should be using this anyway if your using CI's form validation.
Can't you simply use the $_POST data to display the second form?
You could store the data entered in form 1 in sessions or in the database and display it in the second form. Or as mentioned use $_POST in the second form to retrieve submitted data from the previous.

Resources