Вопрос

I have two fields I want to duplicate using SheepIt: Email-Address and Email-Address-Type. These should be duplicated every time. I have this working already, here is the HTML:

    <div class='form-group'>
        <label>Emails</label>
        <div id='emails-form_controls' class='inline'>
            <div id='emails-form_add' class='inline'>
                <a class='btn action highlight-color'>
                    <span>Add email</span>
                </a>
            </div>
        </div>
        <div id='emails-form'>
            <div id='emails-form_template' class='multiple-form'>
                <input type='text' name='emails[#index#]' id='emails-form_#index#_email' class='form-control auto-width inline' />
                <select name='etypes[#index#]' id='etypes-form_#index#_etype' class='form-control auto-width inline'>
                    <option value='1'>Default</option>
                    <option value='2'>Personal</option>
                    <option value='3'>Work</option>
                </select>
                <a id='emails-form_remove_current'>
                    <i class='fa fa-times-circle delete-icon'></i>
                </a>
            </div>
            <div id='emails-form_noforms_template'>No emails</div>
        </div>
    </div>

When I try to do data injection I follow the SheepIt example on their website so I added this Javascript:

    var sheepItForm = jQuery("#emails-form").sheepIt({
        separator: "",
        allowRemoveLast: true,
        allowRemoveCurrent: true,
        allowRemoveAll: false,
        allowAdd: true,
        allowAddN: true,
        maxFormsCount: 0,
        minFormsCount: 0,
        iniFormsCount: 0,
        data: [{'email':'workemail@work.com', 'etype': '3'}]
    });

I'm seeing the "workemail@work.com" show up, but the type doesn't change. NOTE: I am aware of SheepIt's bug with the select tag and have already fixed it; I have it working already on another dropdown field

My question becomes, simply:

How do I get the second field of a multi-field SheepIt form to populate with data injection?

Это было полезно?

Решение

Figured it out by debugging, line-by-line, the SheepIt code!

This line was what was messing me up:

<select name='etypes[#index#]' id='etypes-form_#index#_etype' class='form-control auto-width inline'>

SheepIt was looking for it by ID, but using the name of the form instead: emails

Updating that line to the following made everything work wonderfully:

<select name='etypes[#index#]' id='emails-form_#index#_etype' class='form-control auto-width inline'>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top