using the hook of the plugin jquery.cloneya

3

I'm using the plugin from jquery.cloneya which is a plugin to clone forms that were already included in an template of an admin panel I am using. I did not quite understand how to use the hook of this plugin to increment the name of an input whenever it is cloned .

For example: Click on the "+" sign and clone one or two fields together. These two fields have their name incremented this way > " name='produtos[qtd][2]' ", the index of the first input beginning with " [qtd][0] ".

I asked the developer of the plugin if it was possible to make the clone and increment the names and he replied the following:

"Yes, it is. Ideally, due to the nature of cloned form elements, the names should be name [], so that the values can be processed as arrays. can plug into the custom event - clone_form_input .

See: link .

    
asked by anonymous 02.04.2014 / 22:17

1 answer

1

Unfortunately, the plugin's documentation is very weak, making it very difficult to use.

Anyway I created an example of how to create a pure Javascript form. I think you're going to have to end up accepting that same solution.

HTML

<button id='botao'>
    Adicione um formulário
</button>

<div id='formulario'>
    <form id='form' action='#'>
        <input type='submit' id='submit'></input>
    </form>
</div>

Javascript

var sequencia = 0;

var form = document.getElementById('form');
var submit = document.getElementById('submit');

var cria_formulario = function() {

    var input = document.createElement('input');
    input.setAttribute('type', 'text');
    input.setAttribute('name', 'entrada[' + sequencia + ']');
    input.setAttribute('value', 'entrada[' + sequencia + ']');
    sequencia += 1;

    form.removeChild(submit);
    form.appendChild(input);
    form.appendChild(document.createElement('br'));
    form.appendChild(submit);
};

var botao = document.getElementById('botao');
botao.onclick = function() {
    cria_formulario();
}

JSFiddle

View in JSFiddle .

    
13.04.2014 / 21:10