Hi ...

For more User convenience it would be cool, when mapping the tokens for the fields, that we are able to click on a token and it inserts automaticly as text in the textarea above.

Sure no big thing, but would great.

the other thing would be to create kind of search for the tokens, with auto-complete functionallity

Comments

wizonesolutions’s picture

Version: 6.x-1.9 » 6.x-1.x-dev

Good idea zewa.

lefnire what do you think? I think this functionality would probably be better served by separate modules that provide this functionality. Or maybe there is an API-style module that would let us implement this easily? If not...maybe it's time to make one :)

zewa’s picture

if there's anybody like me who can't wait here the quick solution for clickable Tokens

1.) create a file called "fillpdf_admin.js" inside the fillpdf folder
2.) open file and enter following text

$(document).ready(function() {
  $('#token_help').children('tbody').children('tr').each(function() {
    $(this).children('td').eq(0).click(function() {
        //console.log($(this));
        $('#edit-value').html($('#edit-value').html() + $(this).html()); 
    });
  });
});

3.) open file token.pages.inc in token folder
4.) edit inside the function "theme_token_help" the last $output line

From this:
$output = theme('table', $headers, $rows, array('class' => 'description'));

To this:
$output = theme('table', $headers, $rows, array('class' => 'description', 'id' => 'token_help'));

5.) Open file "fillpdf.admin.inc", search for function "fillpdf_field_edit" and append in first line following:

drupal_add_js(drupal_get_path("module", "fillpdf") . "/fillpdf_admin.js");

6.) Clear Cache and enjoy :)

EDIT:
Anyway this is just a quick hack, and the JS for sure isn't the fastest, but if you guys have customers, who are nervous and can't wait, it will surely do for the moment :)

zewa’s picture

Well here comes the vital part ... the search box + add button

in fillpdf.module define following inside menu function

$items['fillpdf/autocomplete/token'] = array(
    'type' => MENU_CALLBACK,
    'access arguments' => array('access content'),
    'page callback' => 'fillpdf_token_autocomplete',
 );

than create the new function somewhere in fillpdf.module

function fillpdf_token_autocomplete($searchText) {
  $full_list = token_get_list("all");

  $result = array();
  foreach ($full_list as $key => $category) {
    foreach ($category as $token => $description) {
      if(strstr($token, $searchText))
        $result[$token] = $token;
    }
  }

  echo drupal_to_js($result);
  
  // exit, to prevent your results form hitting the theme layer
  exit();
}

now in fillpdf.admin.inc function "fillpdf_field_edit" after $form['pdf_key'] array add this

$form['mytoken_auto'] = array(
    '#size' => '30',
    '#weight' => '3',
		'#suffix' => '<input type="button" id="token_insert_btn" value="Insert" />',
    '#type' => 'textfield',
    '#autocomplete_path' => 'fillpdf/autocomplete/token',
    '#title' => 'Token search',
);

now you need a js function inside that form like my before post with fillpdf_admin.js, and there add following code

$('#token_insert_btn').click(function() {
    if($('#edit-mytoken-auto').val() != '')
    {
      $('#edit-value').html($('#edit-value').html() + '[' + $('#edit-mytoken-auto').val() + ']');
      $('#edit-mytoken-auto').val('');
      $('#edit-mytoken-auto').focus();
    }
  });

And there you go ...
if someone could make a patch out of this, it would be great because, still I dont get it how to do it, and i've also got a dozen other custom corrections in the module

wizonesolutions’s picture

Status: Active » Postponed

Still undecided as to how best to fit this into the module. It would improve the usability, but is there already a token autocomplete module that could perhaps be leveraged? Need to come back to this.

wizonesolutions’s picture

Status: Postponed » Closed (won't fix)

This is in 7.x already, and I think it's in more recent versions of Token too, so closing.