Browse files

Exclude nested form's blueprints from dom_ready handler to prevent pr…

…ocessing field twice(once when page is loaded, and once when 'Add new' button is pressed)
  • Loading branch information...
1 parent a6b65ec commit f55588c6aaec74ed83419f715792e6fd25195642 @mshibuya mshibuya committed Apr 24, 2012
Showing with 10 additions and 10 deletions.
  1. +10 −10 app/assets/javascripts/rails_admin/ra.widgets.coffee
View
20 app/assets/javascripts/rails_admin/ra.widgets.coffee
@@ -4,7 +4,7 @@ $(document).live 'rails_admin.dom_ready', ->
# colorpicker
- $('[data-color]').each ->
+ $('form [data-color]').each ->
that = this
$(this).ColorPicker
color: $(that).val()
@@ -20,24 +20,24 @@ $(document).live 'rails_admin.dom_ready', ->
# datetime
- $('[data-datetimepicker]').each ->
+ $('form [data-datetimepicker]').each ->
$(this).datetimepicker $(this).data('options')
# enumeration
- $('[data-enumeration]').each ->
+ $('form [data-enumeration]').each ->
$(this).filteringSelect $(this).data('options')
# fileupload
- $('[data-fileupload]').each ->
+ $('form [data-fileupload]').each ->
input = this
$(this).find(".delete input[type='checkbox']").live 'click', ->
$(input).children('.toggle').toggle('slow')
# filtering-multiselect
- $('[data-filteringmultiselect]').each ->
+ $('form [data-filteringmultiselect]').each ->
$(this).filteringMultiselect $(this).data('options')
if $(this).parents("#modal").length # hide link if we already are inside a dialog (endless issues on nested dialogs with JS)
$(this).parents('.control-group').find('.btn').remove()
@@ -46,7 +46,7 @@ $(document).live 'rails_admin.dom_ready', ->
# filtering-select
- $('[data-filteringselect]').each ->
+ $('form [data-filteringselect]').each ->
$(this).filteringSelect $(this).data('options')
if $(this).parents("#modal").length # hide link if we already are inside a dialog (endless issues on nested dialogs with JS)
$(this).parents('.control-group').find('.btn').remove()
@@ -55,7 +55,7 @@ $(document).live 'rails_admin.dom_ready', ->
# nested-many
- $('[data-nestedmany]').each ->
+ $('form [data-nestedmany]').each ->
field = $(this).parents('.control-group').first()
nav = field.find('> .controls > .nav')
content = field.find('> .tab-content')
@@ -81,7 +81,7 @@ $(document).live 'rails_admin.dom_ready', ->
# nested-one
- $('[data-nestedone]').each ->
+ $('form [data-nestedone]').each ->
field = $(this).parents('.control-group').first()
nav = field.find("> .controls > .nav")
content = field.find("> .tab-content")
@@ -100,7 +100,7 @@ $(document).live 'rails_admin.dom_ready', ->
# polymorphic-association
- $('[data-polymorphic]').each ->
+ $('form [data-polymorphic]').each ->
type_select = $(this)
field = type_select.parents('.control-group').first()
object_select = field.find('select').last()
@@ -124,7 +124,7 @@ $(document).live 'rails_admin.dom_ready', ->
# ckeditor
- $('[data-richtext=ckeditor]').each ->
+ $('form [data-richtext=ckeditor]').each ->
window.CKEDITOR_BASEPATH = '/assets/ckeditor/'
options = $(this).data('options')
if not window.CKEDITOR

4 comments on commit f55588c

@ehoch

Mine is still duplicating the CKEditor field whenever I press a "add new" button. Anyone else?

@mshibuya
Collaborator

I've confirmed that issue.

Now I've pushed 230e3c5 to master, which is workaround for this issue, but it doesn't solve the problem completely.
(For example, editing CKEditor field content and then pressing 'Add new' button of nested form causes CKEditor field content to be reset.)

@bbenezech
Do you have any idea to solve these issue?

@bbenezech
Collaborator

Hello bro.

CKeditor populates the textarea at commit time with a hook. So when we reset it, all new content is wiped. :/

Testing if the field is not already in CKeditor's form would be a nice idea. (testing class or whatever CK adds around the textarea)

Something like

https://github.com/sferik/rails_admin/blob/230e3c560e527924f311095a65b8a1cf12e38d0d/app/assets/javascripts/rails_admin/ra.widgets.coffee#L127

    $('form [data-richtext=ckeditor]:not(.ckeditored)').each ->
      window.CKEDITOR_BASEPATH = '/assets/ckeditor/'
      options = $(this).data('options')
      if not window.CKEDITOR
        $(window.document).append('<script src="' + options['jspath'] + '"><\/script>')
      if instance = window.CKEDITOR.instances[this.id]
        window.CKEDITOR.remove(instance)
      window.CKEDITOR.replace(this, options['options'])
      $(this).addClass('ckeditored')

I can't test it right now, but this should do it.

@mshibuya
Collaborator

Works perfectly👏, thanks!

Please sign in to comment.