CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Autocomplete for profile current_employer in block - wrong url?
Pages: [1]

Author Topic: Autocomplete for profile current_employer in block - wrong url?  (Read 1296 times)

david.a.king

  • I’m new here
  • *
  • Posts: 25
  • Karma: 0
  • CiviCRM version: 3.4.5
  • CMS version: drupal 6.22
  • MySQL version: 5.2
  • PHP version: 5.3
Autocomplete for profile current_employer in block - wrong url?
August 15, 2011, 08:18:08 am
Hi, I'm trying to use the code from http://en.flossmanuals.net/civicrm/ch066_api/ to add autocomplete for the current employer field in a profile which i'd like to show in a block

Code: [Select]
<script>
jQuery(document).ready(function($){
  $('#current_employer').crmAutocomplete({params:{contact_type:'Organization'}});
});
</script>

I'm using the "html form snippet" feature to make my profile block, which is perhaps not the ideal way to do it (hardcoded and unnecessary extras?)

So firstly not sure if that would cause any issues..

The above code adds the magnifying glass to the field but doesn't return any results. Looking in firebug it's getting a 404

Code: [Select]
http://MYURL/civicrm/ajax/rest?rowCount=35&json=1&fnName=civicrm/contact/search&contact_type=Organization&return[sort_name]&return[email]&&s=g&limit=25&timestamp=1313420215182&sort_name=g
and i can see that it's not pointed to the right location - it should be

Code: [Select]
http://MYURL/MYSUBFOLDER/civicrm/ajax/rest?etc
i.e. it's just going to the server root rather than the actual drupal install directory.

the drupal and civi base seem to be set correctly if i look at the settings.php - i don't know if it would use that or if there's another setting elsewhere, or whether it's another problem entirely?

thanks!
david

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Autocomplete for profile current_employer in block - wrong url?
August 15, 2011, 08:56:11 am
Hi,

Code: [Select]
//If you do not use clean urls on the root of your domain, you have to define a variable to set the url of the server to be used for the rest
<script type="text/javascript">
var options {ajaxURL:"{$config->userFrameworkResourceURL}";
</script>


That should do the trick.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

david.a.king

  • I’m new here
  • *
  • Posts: 25
  • Karma: 0
  • CiviCRM version: 3.4.5
  • CMS version: drupal 6.22
  • MySQL version: 5.2
  • PHP version: 5.3
Re: Autocomplete for profile current_employer in block - wrong url?
August 15, 2011, 09:51:21 am
hi Xavier, i couldn't get that code to work, is it definitely correct? says "missing ; before statement"

either way, if i just put {$config->userFrameworkResourceURL} in a template it seems to give the expected result:

Code: [Select]
http://MYURL/MYSUBFOLDER/sites/all/modules/civicrm/ ajaxURL: "/MYSUBFOLDER/civicrm/ajax/rest"
i do have clean urls enabled and disabling them gives the same original error, if that matters.

thanks,
david
« Last Edit: August 15, 2011, 10:06:05 am by david.a.king »

david.a.king

  • I’m new here
  • *
  • Posts: 25
  • Karma: 0
  • CiviCRM version: 3.4.5
  • CMS version: drupal 6.22
  • MySQL version: 5.2
  • PHP version: 5.3
Re: Autocomplete for profile current_employer in block - wrong url?
September 13, 2011, 06:06:25 am
had another look at this, seems that there is some issue regarding building the contactURL in rest.js

If i adjust the ajaxURL on line 56 of rest.js to

Code: [Select]
ajaxURL: '/[MYSUBFOLDER]/civicrm/ajax/rest',
it works - so it definitely seems that the site install path is lost as you suggested, yet the autocomplete works on all standard civicrm forms, so is it specifically to do with using it from a .tpl?

i still can't work out how this is supposed to be implemented, as i said it gives an error and i'm not a real coder.. looks like it would indeed solve my problem if it worked though?

Code: [Select]
//If you do not use clean urls on the root of your domain, you have to define a variable to set the url of the server to be used for the rest
<script type="text/javascript">
var options {ajaxURL:"{$config->userFrameworkResourceURL}";
</script>

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Autocomplete for profile current_employer in block - wrong url?
September 13, 2011, 06:37:41 am
Oops, it seems, can you try:


Code: [Select]
<script type="text/javascript">
var options = {ldelim}ajaxURL:"{$config->userFrameworkResourceURL}"{rdelim};
</script>

if you still have the error message, try:

Code: [Select]
var options = {ajaxURL: "/[MYSUBFOLDER]/civicrm/ajax/rest"};
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

david.a.king

  • I’m new here
  • *
  • Posts: 25
  • Karma: 0
  • CiviCRM version: 3.4.5
  • CMS version: drupal 6.22
  • MySQL version: 5.2
  • PHP version: 5.3
Re: Autocomplete for profile current_employer in block - wrong url?
September 13, 2011, 08:00:45 am
thanks - no longer gives me a syntax error but doesn't work either (neither of them).

in firebug:
Code: [Select]
GET /civicrm/ajax/rest?...
when it should be:
Code: [Select]
GET /[MYSUBFOLDER/civicrm/ajax/rest?..
i'm putting this in a report .tpl btw in this particular case, that probably matters!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Autocomplete for profile current_employer in block - wrong url?
September 13, 2011, 08:14:56 am
Can you pm me an access? Not sure I understand what's going on.

Alternatively, you can patch the rest.js file indeed

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

david.a.king

  • I’m new here
  • *
  • Posts: 25
  • Karma: 0
  • CiviCRM version: 3.4.5
  • CMS version: drupal 6.22
  • MySQL version: 5.2
  • PHP version: 5.3
Re: Autocomplete for profile current_employer in block - wrong url?
September 14, 2011, 06:39:19 am
thanks, though it would be good to know why, i think i'll just have the alteration to rest.js then - when it goes live it will be at the root anyway, so should work normally and be fine for updates etc.


david.a.king

  • I’m new here
  • *
  • Posts: 25
  • Karma: 0
  • CiviCRM version: 3.4.5
  • CMS version: drupal 6.22
  • MySQL version: 5.2
  • PHP version: 5.3
Re: Autocomplete for profile current_employer in block - wrong url?
September 19, 2011, 04:28:23 pm
ok here's an odd twist - it's not the same issue but related so apologies if it shouldn't be in this thread.

When using the method mentioned below to add autocomplete, it only works as expected for the first 2 letters - after that it will visibly list the correct item if it was returned from that 2 letter filter, but won't let you click on it, and in firebug says "Value is undefined"

If i do it directly in the address bar, i don't get any errors so maybe it's something to do with multiple requests?
Code: [Select]
civicrm/ajax/rest?rowCount=35&json=1&fnName=civicrm/contact/search&return[sort_name]&&s=mycontactname&limit=25&timestamp=1316474305351&sort_name=mycontactname
changing the settings in rest.js
Code: [Select]
  width: 250,
      delay:100,
      max:25,
      minChars:0,
      selectFirst: true

i.e. minChars doesn't help, though if i lower the "max" to 20 i can get results for 3 letters successfully, if i change it to 2 i can get 4!

any ideas?

thanks,
david

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Autocomplete for profile current_employer in block - wrong url?

This forum was archived on 2017-11-26.