jeudi 11 octobre 2018

Take values from a dinamic html generate for js with laravel

This is my first question here! So, be nice :)

I can not take the values ​​of the form when more than one professional is charged dynamically. I leave my html code:

<div class="" id="padre">
                <div id="hijo" name="">
                    <h3>A 9. Profesional Interviniente:</h3>
                    <div class="form-group" >
                        <select class="form-control" name="profesional_id[]">
                            <option value="">Profesional que interviene</option>
                            @foreach ($datosProfesional as $profesional)
                                <option value=""></option>
                            @endforeach
                        </select>
                        {!! $errors->first('profesional_id', '<p class="help-block" style="color:red";>:message</p>') !!}
                    </div>

                    <div class="form-group" >
                        <label for="datos_profesional_interviene_desde[]">A 9.3 Interviene desde:</label>
                        <input type="date" class="form-control" name="datos_profesional_interviene_desde" id="datos_profesional_interviene_desde" value="">
                        {!! $errors->first('datos_profesional_interviene_desde', '<p class="help-block" style="color:red";>:message</p>') !!}
                    </div>

                    <div class="form-group" >
                        <label for="datos_profesional_interviene_hasta[]">A 9.4 Interviene hasta:</label>
                        <input type="date" class="form-control" name="datos_profesional_interviene_hasta" id="datos_profesional_interviene_desde" value="">
                        {!! $errors->first('datos_profesional_interviene_hasta', '<p class="help-block" style="color:red";>:message</p>') !!}
                    </div>

                    <div class="form-group" >
                        <label for="profesionalactualmente_id">A 9.5 Actualmente Interviene:</label>
                        <select class="form-control" name="profesionalactualmente_id[]">
                            <option value=""> </option>
                            @foreach ($datosIntervieneActualmente as $profesionalInterviene)
                                <option value=""></option>
                            @endforeach
                        </select>
                        {!! $errors->first('profesionalactualmente_id', '<p class="help-block" style="color:red";>:message</p>') !!}
                    </div>
                </div>
            </div>

The javascript function that dynamically generates the fields:

<script>
            $(document).ready(function(){
                var nueva_entrada ='';
                $(document).ready(function() {
                 nueva_entrada = $('#padre').html();
                });

                $("#anadir").click(function(){
                    $("#padre").append(nueva_entrada);
                });

            });

            function borra() {
               var padre = document.getElementById("padre");
               var hijo = document.getElementById("hijo")
                padre.removeChild(hijo);
            }
        </script>

How could I take more than one professional with laravel? Now I'm trying this

request()->validate([
                            'profesional_id' => 'required',
                            'datos_profesional_interviene_desde' => 'required',
                            'datos_profesional_interviene_hasta' => 'required',
                            'profesionalactualmente_id' => 'required'                           
                            ],

                            [
                            'profesional_id.required' => 'Este campo es obligatorio',
                            'datos_profesional_interviene_desde.required' => 'Este campo es obligatorio',
                            'datos_profesional_interviene_hasta.required' => 'Este campo es obligatorio',
                            'profesionalactualmente_id.required' => 'Este campo es obligatorio'
                            ]);

        $profesionales = collect(['profesional_id', 'datos_profesional_interviene_desde', 'datos_profesional_interviene_hasta', 'profesionalactualmente_id']);

I hope that everyone can help me

regards



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire