Javascript to select multiple keywords.

Help
dharhas
2009-01-07
2013-05-28
  • dharhas

    dharhas - 2009-01-07

    Hi,

    I was wondering if anyone had done this or something similar with refbase or if anyone can point me to some references on how to do this.

    I want to allow users to use a standard list of keywords to fill in the keywords fields of a record.

    ie. Next to the keyword field have a button which will open a box or list where they can select multiple predefined keywords and have those fill the keyword text box. I would also like them to be able to type additional keywords that are not on the list directly in the text box.

    thanks,

    - dharhas

     
    • Matthias Steffens

      Hi dharhas,

      sorry for the late reply!

      > I want to allow users to use a standard list of keywords to fill in
      > the keywords fields of a record.

      Yes, I agree this would be a very useful feature.

      > ie. Next to the keyword field have a button which will open a box or
      > list where they can select multiple predefined keywords and have
      > those fill the keyword text box. I would also like them to be able
      > to type additional keywords that are not on the list directly in the
      > text box.

      An easy way of implementing this would be to make use of the auto-completion functionality provided by the Prototype & script.aculo.us JavaScript frameworks (which refbase already uses).

      E.g., one could supply a static list of keywords to function 'buildSuggestElements()' (in 'includes/include.inc.php').

      To do so, open file 'record.php' and replace this line:

      $keywordsSuggestElements = buildSuggestElements("keywordsName", "keywordsSuggestions", "keywordsSuggestProgress", "col-keywords-", "\t\t", "';'");

      with this one:

      $keywordsSuggestElements = buildSuggestElements("keywordsName", "keywordsSuggestions", "keywordsSuggestProgress", "col-keywords-", "\t\t", "';'", 0.8, 2, "''", "keywords.html", "", "");

      Then create a 'keywords.html' file within your refbase root directory, and enter your standard list of keywords as an unordered HTML list, like this:

      <ul>
          <li>one</li>
          <li>two</li>
          <li>three</li>
          <li>four</li>
          <li>five</li>
      </ul>

      Now, after reloading 'record.php' in your browser, your standard list of keywords will be presented underneath the Keywords field whenever the user types a keyword. The user can select a keyword from your standard list, or continue typing his own keywords. As usual, multiple keywords can be separated by a semicolon character.

      Would such a setup suit your needs?

      Ideally, the standard list of keywords would be offered in *addition* to the current auto-completion feature, and not instead of it. But I'm sure this could be also implemented with a bit of tweaking.

      Please let us know if you come up with something better.

      HTH, Matthias

       
    • dharhas

      dharhas - 2009-01-21

      Thanks for your reply. I'll try implementing your suggestion when I get a chance. Busy with other stuff right now...

      Would your solution actually display the list of keywords or would it be more like the way the autocomplete presently works but looking through the list of fixed keywords rather than the database. Ideally, I need to display the list of keywords because some of them may not be something the data enters may think of but would that would obviously apply if it was on the list.

      > Ideally, the standard list of keywords would be offered in *addition* to the current auto-completion
      > feature, and not instead of it. But I'm sure this could be also implemented with a bit of tweaking.

      Ideally this is what I need to do. I'll have to see if I understand how this could be done.

      thanks,

      - dharhas

       
    • Matthias Steffens

      Hi dharhas,

      > Would your solution actually display the list of keywords or would
      > it be more like the way the autocomplete presently works but looking
      > through the list of fixed keywords rather than the database.

      The former, i.e. the given solution will always display the entire list of keywords, no matter what the user types. The user can then select a given keyword from the list (via the mouse or the cursor+return keys), or go ahead typing his own keywords.

      > Ideally, I need to display the list of keywords because some of them
      > may not be something the data enters may think of but would that
      > would obviously apply if it was on the list.

      Yes, this is how the given solution works.

      If instead real auto-completion from the fixed list of keywords is desired, one would need to implement a little PHP script ('keywords.php' instead of 'keywords.html') which would return only matching keywords.

      > > Ideally, the standard list of keywords would be offered in
      > > *addition* to the current auto-completion feature, and not instead
      > > of it. But I'm sure this could be also implemented with a bit of
      > > tweaking.
      >
      > Ideally this is what I need to do. I'll have to see if I understand
      > how this could be done.

      Here's another suggestion that would allow to present *both*, dynamic auto-completions as well as your fixed keyword list, within the keyword dropdown menu.

      Instead of the previously given solution, you could patch function 'searchSuggestions()' in file 'opensearch.php':

      1. At the top of that function (just after the line that says "global $client;"), add this line:

        include 'includes/keywords.inc.php'; // include fixed list of keywords

      2. Now make a new file (named 'keywords.inc.php') within the refbase 'includes/' directory that is inside your main refbase script directory, and add your list of keywords in that file (as a PHP array), e.g. like this:

      <?php
        $fixedKeywords = array(
                               "",
                               "one",
                               "two",
                               "three",
                               "four",
                               "five",
        );
      ?>

      The first empty array item just serves as a separator. You could also give some explanatory text there -- or leave it out.

      3. Back in function 'searchSuggestions()', replace these two lines:

              sort($outputDataArray);
            }

      with these lines:

              sort($outputDataArray);
            }
        }

        // when auto-completing the 'keywords' field, append the fixed list of
        // keywords to the array of found search suggestions:
        if ($searchSuggestionsField == "keywords")
          $outputDataArray = array_merge($outputDataArray, $fixedKeywords);

        if (!empty($outputDataArray))
        {

      Now switch back to your browser, open 'record.php', and start typing in the "Keywords" field. Your fixed list of keywords should be presented in the auto-completion list, below the list of dynamic auto-completions.

      I hope this helps. Let us know if you've got further questions.

      Matthias

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks