Category Archives: JavaScript

Refresh Typeahead Suggestions

var $name = $('#name');
var nameEntered = $name.typeahead('val');
$name.typeahead('val', '').typeahead('val', nameEntered);

This is great if you add an entry behind the scenes and then want it to show up in the list of suggestions without having to re-trigger the suggestion refresh manually.


Override X-editable Value After Save

I wasn’t able to find a way to set an X-editable field to a specific value after a submit. After poking around in the source for X-editable I noticed the following:

//if success callback returns object like {newValue: <something>} --> use that value instead of submitted
//it is useful if you want to change value in url-function
if(res && typeof res === 'object' && res.hasOwnProperty('newValue')) {
  newValue = res.newValue;

Once I found this, setting the field to the proper value was very straightforward:

  success: function editable_success(response){
    var json_response = JSON.parse(response);
    if(json_response.success) {
      if(json_response.new_value) {
        return {newValue: json_response.new_value};