Download & Extend

Add "autocomplete" to Fallback Widget

Project:Node Reference URL Widget
Version:6.x-1.1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)
Issue tags:Science Collaboration

Issue Summary

In my case, I would need users to still be able to use the autocomplete widget if there is nothing in the URL to populate the reference.

Comments

#1

I've got this as a TODO already in code, and all the code is already in place as far as I could figure out. I ran into a problem where the value of the autocomplete field wasn't being saved properly. Anyone that has an idea on what could be wrong with the existing code, please take a look.

Just uncomment the line around 127 in nodereference_url.module:

            // TODO: Get autocomplete fallback working. Currently looses value on save.
            //'autocomplete' => t('Use autocomplete widget'),

#2

Any luck on this?

#3

No, I gave it another attempt recently but still have not been able to get it to work properly.

#4

Subscribe

#5

Didn't need this, but I like this module and was curious if I could figure it out

The issue is in the validate function of the node reference element it expects it to be formated as a multi value, ie
0=> nid => val

instead node reference is coming back as
nid=> val

Tried to make it so the $element was a pretend multi value etc, but didn't full it, but figured a work around

Add a validation function to nodereference (Un needed info, but due to an unshift in nodereference it's validation function ALWAYS runs first).

<?php
            $element
= array(
           
'#type' => 'nodereference_autocomplete',
           
'#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
           
'#value_callback' => 'nodereference_autocomplete_value',
                   
'#element_validate'=> array('nodereference_url_autocomplete_validate')
          );
?>

Then the grand validation function...

<?php
function nodereference_url_autocomplete_validate($element, &$form_state) {
   
$form_state['values'][$element['#field_name']] = array($form_state['values'][$element['#field_name']] );

}
?>

Basically, get it into the format that nodereference field wants to process.

(Actually, I think this is a nodereference issue more than a node reference url, possible. Should handle single output from nodereference single widget, but doesn't. Check the 'validate' inside of field_info of nodereference. )

#6

Nice hefox! Yeah this would definitely be great to fix in Node Reference if possible. I haven't tried you approach but it looks like a good canidate for the module if we can't fix it in Node Reference.

#7

I'm still not sure if it is a node reference bug or not; in general the expected format of cck field with delta=>value=>? If so, then it's a node reference. But if single instantaneous of a cck field with the value return as value=> is supportable.. then it is a node reference issue.

And oops, the issue is in the implementation of nodereference_field hook when it's validating the output

<?php
      $ids
= array();
      foreach (
$items as $delta => $item) {
         
//  etc. etc.
?>

If I was to fix it, i'd put before the foreach a

<?php
if (array_key_exists('nid',$items)) $items = array($items);
?>

#8

Congratulations, hefox! This helpful effort turns out to be related to a requested feature on a project you are working on! #opensource-awesomeness

Came here to file a feature request; only bumping and subscribing for now.

ben, Agaric

#9

I would love this functionality too, it would be very helpful on a site i'm building.
thanks for working on this!

hence, subscribing

#10

I tried explaining what was causing the node reference issue in cck issue queue (along with another tweek i'd like), but I either didn't manage to make sense (based on the response I got) or didn't make convincing argument to change it in core cck (the issue http://drupal.org/node/530534 ). looks like this is something that needs to be done in nodereference_url even if it's an ugly workaround.

Anther way is to make two widgets, one for multi widget fallback (select, checkboxes) and one for autocomplete fallback. Would be some duplicate code, but would fix the multi issue.

#11

Thanks for looking into this hefox,

Do you have any ideas on how to make a workaround that does not involve modifying node-reference module?

#12

^ the workaround is above number #5 (should still work, haven't tested since nodereference_url was updated); the part about that is that it could be solved via both altering node reference or doing the work around; I just dislike the uglyness of the workaround.

#13

sub

#14

Status:active» needs review

Thanks hefox for taking the time to sort this out. I've rolled your solution from #5 into a patch, tested and works for me.

AttachmentSize
nodereference_url-432978-14.patch 1.9 KB

#15

excellent, that works perfectly - thanks very much

#16

Thanks malclocke for the patch! We just should be using form_set_value() rather than manually assigning the $form_state value in nodereference_url_autocomplete_validate(), since that will break when used with field groups.

#17

Re-rolled using form_set_value() (I think correctly). Tested and working with nodereference inside and outside a fieldgroup.

AttachmentSize
nodereference_url-432978-17.patch 1.89 KB

#18

The patch works! Thanks a bunch!

#19

OK, I tested it out on my site and it seems to work great. Am I supposed to change it to "RTBC" then or just post that I think it works great and that it's ready?

#20

Status:needs review» reviewed & tested by the community

Yep, definitely RTBC. I'll give this one last look before committing next time I'm working on the module.

#21

Works for me, but the other thing needed for this is the Autocomplete matching selection (Starting with or Contains). It's defaulting to Contains.

#22

Status:reviewed & tested by the community» fixed

Committed #17, great work malclocke!

#23

THX malclocke!
Very nice patch!

#24

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here