Sha256: d7b19692e215ec37a05b48292895bf275abec990612b55536f9222ffecf36b4a
Contents?: true
Size: 1.08 KB
Versions: 4
Compression:
Stored size: 1.08 KB
Contents
class DynamicField constructor: (@templates = {}) -> remove_fields: (button) -> $(button).closest('.fields').remove() add_fields: (button, type, content) -> new_id = new Date().getTime() regexp = new RegExp('new_' + type, 'g') $(button).before(content.replace(regexp, new_id)) nest_fields: (button, type) -> new_id = new Date().getTime() id_regexp = new RegExp('new_' + type, 'g') template = @templates[type] object_name = $(button).closest('.fields').attr('data-object-name') sanitized_object_name = object_name.replace(/\]\[|[^-a-zA-Z0-9:.]/g, '_').replace(/_$/, '') template = template.replace(/new_object_name\[/g, object_name + "[") template = template.replace(/new_object_name_/, sanitized_object_name + '_') $(button).before(template.replace(id_regexp, new_id)) # --- # main # --- dynamic_field = new DynamicField $(document).on('click', '.add_fields', -> dynamic_field.add_fields(this, $(this).data('fieldType'), $(this).data('content')) false ) $(document).on('click', '.remove_fields', -> dynamic_field.remove_fields(this) false )
Version data entries
4 entries across 4 versions & 1 rubygems