简体   繁体   中英

How to set default value for input with type of date in jquery repeater?

I use jquery repeater in my project. When I try set default value for input type date return error:

jquery.repeater.js:688 Uncaught TypeError: Cannot read property 'set' of undefined

Form code:

<form action="" class="repeater" enctype="multipart/form-data">
  <div data-repeater-list="users">
    <div data-repeater-item>
      <input type="text" name="name"/>
      <input type="email" name="email"/>
      <select name="sex">
        <option value="0" selected>Male</option>
        <option value="1">Female</option>
      </select>
      <input type="date" name="birthday"/>
      <input data-repeater-delete type="button" value="Delete"/>
    </div>
  </div>
  <input id="add" data-repeater-create type="button" value="Add User"/>
</form>

Javascript code:

$(document).ready(function () {
    'use strict';
    $('.repeater').repeater({
        defaultValues: {
            'name': 'User',
            'email': 'user@gmail.com',
            'sex': '0',
            'birthday': "1990-09-10"
        },
        show: function () {
            $(this).slideDown();
        },
        hide: function (deleteElement) {
            if(confirm('Are you sure you want to delete this element?')) {
                $(this).slideUp(deleteElement);
            }
        },
        ready: function (setIndexes) {

        }
    });
    $('#add').on('click', function(e){
      var users = $('.repeater').repeaterVal();
      console.log(users);
    });
});

When I don't set default value then I can't get all fields values.

For me I did it the old fashioned way using JQuery

 $(".mydiv-item-repeater").length && $(".mydiv-item-repeater").repeater({
            show: function () {
             $(this).find(".select").val(value);
                $(this).slideDown()
            }, hide: function (e) {
                $(this).slideUp(e)
            }
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM