2

I just added Jeditable plugin to my website. The plugin is available here: http://www.appelsiini.net/projects/jeditable

Everything works fine but I use "loadurl" parameter to load text for editing and I would like to display some text or image while text is loading.

I see the "loadtext" parameter in the defaults and as I understand "Loading..." should be displayed when I click on the text to edit it. Unfortunately, I don't see anything.

    $.fn.editable.defaults = {
    loadtext   : 'Loading...', //Text to display while loading external content.
...
...
    };

How can I display "loadtext" or image from "indicator" parameter while text is loading into textarea?

Thank you.

user
  • 751
  • 2
  • 10
  • 18
  • There are other parameters after "loadtext". – user Feb 15 '14 at 11:43
  • can place your code of what you have done so far – Vickel Feb 15 '14 at 11:43
  • Jeditable's code is here: http://www.appelsiini.net/download/jquery.jeditable.js I don't know why I never see "loadtext" but it exists in the code. – user Feb 15 '14 at 11:53
  • "indicator" is showing up when I save the edited text. As I understand the "loadtext" should be displayed when text is loading into textarea for editing. But I never see the work "Loading..." – user Feb 15 '14 at 12:09
  • maybe because your testing your code on localhost and its simply too fast loading so its never displayed? – Vickel Feb 15 '14 at 12:11
  • @Vickel - nope . . i put a sleep on the server so its not that its too fast – leora Apr 04 '14 at 12:02
  • @user Are you solved your problem ?. I posted the please see it. – dhana Apr 04 '14 at 18:11

3 Answers3

1

I got it to work using ajaxSend and ajaxStop to detect if there is an ajax call to the load url , if so then hide/show the loading label.

HTML:

<div id="editable">select me</div>
<span id="loading">Loading dropdown..</span>

JS:

var load_url = 'http://echo.jsontest.com/insert-key-here/insert-value-here/key/value';

 $('#editable').editable('/Project/UpdatePerson', {
        loadurl: load_url,
        type: 'select',
        loadtext: '<b>Loading Dropdown..." /></b>',
        indicator: '<b>Saving...',
        submit: 'OK',
        callback : function(value, settings) {
            var json = $.parseJSON(value);
            $(this).text(json.Value);

        }
    });

$(document).ajaxSend(function(r,s,t) {
    if($.trim(t.url)==load_url+"?id=editable")
     $('#loading').show();
 });

$(document).ajaxStop(function(r,s) {
   if($('#loading').is(':visible'))
   $('#loading').hide();
});

This is an Updated DEMO

Aditya
  • 4,453
  • 3
  • 28
  • 39
  • I am not looking for a placeholder when saving. I am looking for a placeholder when loading items from select dropdown via ajax – leora Apr 05 '14 at 13:27
  • but that will show the loading on ANY ajax call on the page. I only want it to be applicable to this situation (as i have other non related AJAX calls on the page) – leora Apr 05 '14 at 14:33
  • Precisely for that reason i have an `if` inside the `.ajaxSend` – Aditya Apr 05 '14 at 14:35
  • can you explain your logic around trim(t.url) "?id=editable" ?? how does that define this specific case? – leora Apr 05 '14 at 14:42
  • i am using `$.trim()` to get rid of any spaces from the `AJAX` request url i.e. `t.url` and see if it is equal to our dropdown `load_url+'?id=editable'` (js editable sending a GET param called *editable*), if they match then only i am showing `'Loading dropdown..'` otherwise not.. – Aditya Apr 05 '14 at 14:45
  • 1
    it looks like its working so i accepted the answer . . obviously it feels a bit hacky . . i am now probably going to look into x-editable plugin as that seems to work out of the box but thanks for your help – leora Apr 07 '14 at 19:09
0

sync call deprecated in new jquery, i create fast fix - github fork

sample

    $('.editable').editable('/Project/UpdatePerson', {
        loadurl: '/list/',
        indicator:'<div>loading...</div>',
        type: 'select',

        submit: 'OK',
        callback: function (value, settings) {
            var json = $.parseJSON(value);
            $(this).text(json.Value);
        }
    });
vadimchin
  • 1,477
  • 1
  • 15
  • 17
-2

After understand the jeditable plugin, I found the some strange thing (i.e; To pull the data from the server using ajax call). DEMO URL Here the ajax call they are used in jeditable plugin,

$.ajax({
         type : settings.loadtype,
         url  : settings.loadurl,
         data : loaddata,
         async : false,
         success: function(result) {
            window.clearTimeout(t);
            input_content = result;
            input.disabled = false;
         }
});

In the above ajax call they are used async : false option. It means Ajax Call By default, all requests are sent asynchronously (i.e. this is set to true by default). But in this case asynchronous is false. So it is synchronous request. Here is explanation What does "async: false" do in jQuery.ajax()?

In short, synchronous requests block the execution of code which creates 
"freezing" on the screen and an unresponsive user experience. 

Solution:

Comment async : false option. You can find the async option at line 224 http://pastebin.com/x8QA4a1v

Update: Change the above ajax code with this,

$.ajax({
      type : settings.loadtype,
      url  : settings.loadurl,
      data : loaddata,
      //async : false,
      success: function(result) {
         window.clearTimeout(t);
        content.apply(form, [result, settings, self]);
         input_content = result;
         input.disabled = false;
      }
});
Community
  • 1
  • 1
dhana
  • 6,487
  • 4
  • 40
  • 63
  • changing it to async: true didn't seem to do anything different – leora Apr 04 '14 at 12:24
  • @leora did you tried this url http://codepen.io/anon/pen/qfcDh/. And I have updated my answer. – dhana Apr 04 '14 at 12:38
  • I am trying to get this to work width a select where it would show "loading .. ." while my ajax query is running to get the text – leora Apr 04 '14 at 12:40
  • I didn't get you. Can you explain your problem. – dhana Apr 04 '14 at 12:49
  • to avoid any confusion, i have put my explicit issue into this question: http://stackoverflow.com/questions/22851599/how-can-i-show-a-loading-image-when-jeditable-is-loading-items-for-a-select-drop. I have just updated the question with my code – leora Apr 04 '14 at 12:56
  • @leora I have posted the answer. – dhana Apr 04 '14 at 13:12
  • you proposed solution would cause this to show up when ANY ajax call is run on the page. I have a number of other ajaxs call on the page that are unrelated to this point . . i only want this to happen for this particular call . . – leora Apr 04 '14 at 16:46