Created
July 23, 2017 04:48
-
-
Save aristotelesbr/c8acaa1ce93eb07534548f6673487977 to your computer and use it in GitHub Desktop.
Exemplo nestend_attributes com rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#tipo_doc").change(function() { | |
let id = this.value; | |
$("#campos").html(" ") | |
$.ajax({ | |
headers: { | |
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content') | |
}, | |
url: '/protocolos/campos', | |
type: 'POST', | |
dataType: 'json', | |
data: { "tipo_documento" : id }, | |
success: function(response) { | |
response.forEach(function(element) { | |
let numeroRand = 1000 + Math.floor(Math.random() * 10000); | |
$("#campos").append('<p><label>' + element + '</label></p><input type="text" name="protocolo[protocolo_campos_attributes]['+numeroRand+'][tipo]" id="'+element+'" />') | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment