Last active
August 29, 2015 14:27
-
-
Save willsza/181670e786de2287acdf to your computer and use it in GitHub Desktop.
Alterar todos os IDs dos elementos de uma DIV
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
.form-group.form-inline.fields#teste | |
.form-group | |
= f.input :nexts, label: false, collection: [ "Enviar para","Pergunta","Objetivo","Post","Tarefa","Tag" ], include_blank: false, prompt: "Selecione a Opção", :input_html => { :id => "first_select", :name => 'page[nexts][]' } | |
.form-group | |
= f.input :nexts, label: false, collection: Question.order(:title), include_blank: false, prompt: "Selecione a pergunta", :input_html => { :id => "question_select", :name => 'page[nexts][]' } | |
.form-group | |
= f.input :nexts, label: false, collection: Question.order(:title), as: :grouped_select, group_method: :answer_options, label_method: :content, value_method: :id, include_blank: false, prompt: "Selecione a Reposta", :input_html => { :id => "answer_option_select", :name => 'page[nexts][]' } | |
.form-group | |
= f.input :nexts, label: false, collection: Page.order(:title), include_blank: false, prompt: "Selecione a página", :input_html => { :id => "next_select", :name => 'page[nexts][]' } |
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
.form-group.form-inline | |
= link_to_add_fields '<span class="glyphicon glyphicon-plus"></span> Adicionar nova opção'.html_safe, f |
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
# Script que renderiza os campos configurados | |
$(document).on 'click', 'form .add_fields', (event) -> | |
data = $(this).data('fields') | |
data2 = $(data).find('[id]').add(data).each -> | |
@id = @id + '_1' | |
$('.separator').before($(data2)) | |
event.preventDefault() |
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
# Método que monta a DIV com os campos | |
module PagesHelper | |
def link_to_add_fields(name, f) | |
id = f.object_id | |
fields = render "fields", f: f | |
link_to(name, '#', class: "add_fields btn btn-primary", data: {id: id, fields: fields.gsub("\n", "")}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment