JavaScript - agregar datepicker a formulario

 
Vista:
sin imagen de perfil

agregar datepicker a formulario

Publicado por Maria Lucia (1 intervención) el 08/03/2017 21:59:22
Buenas estoy haciendo un formulario y al agregar una nueva fila a la tabla, los datepicker agregados no muestra la fecha seleccionada, algun consejo? soy principiante y estoy aprendiendo, Desde ya muchas gracias!


script---


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<script>
 
 
$(function() {
    $( "#dateInput" ).datepicker()
	$( "#dateInput2" ).datepicker()
	$.datepicker.regional['es'] = {
 closeText: 'Cerrar',
 prevText: '< Ant',
 nextText: 'Sig >',
 currentText: 'Hoy',
 monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
 monthNamesShort: ['Ene','Feb','Mar','Abr', 'May','Jun','Jul','Ago','Sep', 'Oct','Nov','Dic'],
 dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
 dayNamesShort: ['Dom','Lun','Mar','Mié','Juv','Vie','Sáb'],
 dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sá'],
 weekHeader: 'Sm',
 dateFormat: 'dd/mm/yy',
 firstDay: 1,
 isRTL: false,
 showMonthAfterYear: false,
 yearSuffix: ''
 };
	$.datepicker.setDefaults($.datepicker.regional['es']);
$(function () {
$("#dateInput").datepicker("setDate", "actual");
 
 
        dateFormat: "dd-mm-yy"
    });
 
 
    var i = 1;
    $("#add_row").click(function() {
 
        $("table tr").eq(1).clone().find("input, select").each(function() {
            $(this).attr({
                'id': function(_, id) { return id + 1 },
                'name': function(_, name) { return name + 1 },
                'value': ''
            });
            if($(this).hasClass('dateControl')) {
                $(this).removeClass('hasDatepicker').removeData('datepicker').removeAttr('id')
                    .unbind().datepicker({
                        dateFormat: "dd-mm-yy"
                    });
            }
        }).end().appendTo("table");
        i++;
        $("").select2({
            tags: true
        });
    });
    $("#delete_row").click(function() {
        if (i > 1) {
            $("#actionRow" + (i - 1)).html('');
            i--;
        }
    });
});
</script>


-html----

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<div class="col-md-12">
<label>Proximos Pasos</label>
<table class="table table-bordered table-hover" id="actionTable">
	<thead>
	<tr >
 
	</tr>
	</thead>
	<tbody>
	<tr id='actionRow'>
		<td>
			<input type="text" name='actionInput'  placeholder='Próximos Pasos' class="form-control"/>
		</td>
		<td>
    <input type="text"	class="form-control" name="vac" placeholder="Participantes">
		</td>
		<td>
			<input type="text" name='dateInput2' id="dateInput2" placeholder='Fecha Limite' class="form-control dateControl"/>
		</td>
	</tr>
	</tbody>
</table>
<a id="add_row" class="btn btn-default pull-right">+</a>
<a id='delete_row' class="pull-right btn btn-default">x</a>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de cristian

agregar datepicker a formulario

Publicado por cristian (6 intervenciones) el 09/03/2017 16:05:01
si lo que quieres es un data picker agrega esta funcion,donde ·fecha_nacimiento es el campo input


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$( function() {
    $( "#fecha_nacimiento" ).datepicker({
        dateFormat: "yy-mm-dd"
    });;
  } );
 
  $(function() {
$.datepicker.regional['es'] =
 
 {
 
 closeText: 'Cerrar',
 
 prevText: 'Previo',
 
 nextText: 'Próximo',
 
 monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
 'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
 monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
 'Jul','Ago','Sep','Oct','Nov','Dic'],
 monthStatus: 'Ver otro mes', yearStatus: 'Ver otro año',
 dayNames: ['Domingo','Lunes','Martes','Miércoles','Jueves','Viernes','Sábado'],
 dayNamesShort: ['Dom','Lun','Mar','Mie','Jue','Vie','Sáb'],
 dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sa'],
 dateFormat: 'dd/mm/yy', firstDay: 0,
 initStatus: 'Selecciona la fecha', isRTL: false};
$.datepicker.setDefaults($.datepicker.regional['es']);
   $( "#datapicker" ).datepicker({ minDate: "-1D", maxDate: "+1M +10D" });
 });
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar