Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy loading with "data-source" attribute is not working properly #30

Closed
cemo opened this issue Dec 3, 2012 · 2 comments
Closed

Lazy loading with "data-source" attribute is not working properly #30

cemo opened this issue Dec 3, 2012 · 2 comments

Comments

@cemo
Copy link

cemo commented Dec 3, 2012

I am using x-editable in a lazy way.

<a href="#" data-pk="1" data-name="group" data-type="select" data-original-title="" data-url="/mybackoffice/mylikes/editCategory1" data-source="/mywebsite/getEditableCategories"  data-value="123" data-params="1" class="editable editable-click">

Each of my element has editable class. They remain as a simple element until they will be clicked.

A simple click is adding necessary editable functionality in a lazy way as this:

$('body').on('click', '.editable', function(){
       var $this = $(this);
       if(!$this.data("editable")){
           $this.editable().editable("show");
       }
 })

This pattern will let me to use editable for even ajax responses too. And almost all bootstrap components are working like this.

My problem is that when I have multiple elements with same data-source it is not working as It expected.

It seems as an ajax cache problem because when I change data-source urls as this

data-source="/mywebsite/getEditableCategories?1"
data-source="/mywebsite/getEditableCategories?2"
data-source="/mywebsite/getEditableCategories?3"
data-source="/mywebsite/getEditableCategories?4"  

It is working properly.

I could not create a fiddle example because of not having a server currently to fetch ajax responses.

@vitalets
Copy link
Owner

vitalets commented Dec 3, 2012

hi,

  1. if data-source is url, x-editable cache results after first request for all editables with same source and name. It was done mainly for editable-grids. But now I see it should be an option to disable cache.
    Local solution for your case is to clear cache after any update.
    Please try:
....
if(!$this.data("editable")) {
           $this.editable().editable("show");
           $this.on('save', function() {
                var opts = $(this).data('editable').options;
                $(document).removeData(opts.source+'-'+opts.name);
           });
       }
  1. for jsfiddle you can fork this http://jsfiddle.net/xBB5x/5/ . It includes mockjax plugin allowing to simulate ajax.

@cemo
Copy link
Author

cemo commented Dec 3, 2012

Sorry @vitalets.

There is not a bug. I have used 1.1.0 unfortunately.

http://jsfiddle.net/xBB5x/12/

By the way, I have downloaded at same day you released it which is previous version and it seems that you have fixed it that release :)

@cemo cemo closed this as completed Dec 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants