Skip to content

Instantly share code, notes, and snippets.

@dmsysop
Created February 21, 2019 16:53
Show Gist options
  • Save dmsysop/5fc8a1efe5c269642d2c1c515cb84d00 to your computer and use it in GitHub Desktop.
Save dmsysop/5fc8a1efe5c269642d2c1c515cb84d00 to your computer and use it in GitHub Desktop.
<?
echo '<div id="info_telefone" class="info_telefone" data-array="0">';
echo $this->Form->input('ClientesTelefone.0.telefone', array(
'before' => '<div class="section row mb10"><label class="field-label col-md-2 text-center">' . __("Telefone") . ':</label><div class="col-md-3">',
'between' => '<label class="field prepend-icon">',
'after' => '<label class="field-icon"><i class="fa fa-phone"></i></label></label></div><div id="divBtnAddTelefone" class="col-md-3"><button id="btn_add_telefone" type="button" class="btn btn-info btn-alt btn-block"> + Adicionar Telefone</button></div></div>',
'required' => false,
'class' => 'gui-input clientes_telefone fone',
'label' => false)
);
echo '</div>';
?>
$(function(){
var clonedInput = $('#ClientesTelefone0Telefone').clone();
$('#btn_add_telefone').click(function(e) {
e.preventDefault();
var num = $('.info_telefone').data('array');
var newNum = new Number(num + 1); // the numeric ID of the new input field being added
$('#info_telefone').data('array', newNum);
var newElem = clonedInput.clone().attr('id', 'ClientesTelefone'+ newNum +'Telefone').attr('name', 'data[ClientesTelefone][' + newNum +'][telefone]');
newElem.children(':first').attr('id', 'ClientesTelefone' + newNum +'Telefone').attr('name', 'data[ClientesTelefone][' + newNum +'][telefone]');
$('#ClientesTelefone'+num+'Telefone').after(newElem);
$('.fone').mask('(99) ?99999-9999');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment