Hi there,

I've coded a hack that could be used to provide this feature. Please see http://hygen.net/blog/open-source/drupal-webform_viewreference-module-tw...

Essentially if you are on a node with a webform in a block then that node title in the select list can be set as default!

if ($component['extra']['aslist'] === 'Y' && $component['extra']['multiple'] !== 'Y' && !($component['mandatory'] && !empty($component['value']))) {
        if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1);
        $node = node_load($nodeid);
        $options = array($nodeid => $node->title) + $options;
        //$options = array('' => t('select...')) + $options;
  }

Comments

Anonymous’s picture

this worked great. thanks.
I had to create a backup of the original .inc file.
is there a function override we can do instead? that would be a cleaner solution, IMHO.

d------’s picture

Thanks Careless,

I'm not sure but I think it will be cool if there is an added option for the module that an admin can check to enable this feature. Something like:

Select box defaults to current node title? YES | NO

But it won't be that simple as only a % of users will want to use the module this way.

Over to the maintainers ;)

Dan

Anonymous’s picture

Dan, i noticed that this is actually taking the current node, and adding the list to it, and then adding it to the selections.

is there a way to just tell the argument line you have there to select the current node if it's in the list, rather than add it to the list and then select it.

for example, if i show this as a block on the Frontpage, it shows "Frontpage" as the first selection in the drop down- when it's not even one of the results that should be showing up. Filters are set correctly, but I think the problem lies in this line:

node = node_load($nodeid);

freakalis’s picture

Status: Active » Closed (works as designed)

You can also accomplish this with a hook_form_alter(); Have a look at http://drupal.org/node/1144714 to get an idea how to solve it.

freakalis’s picture

Status: Closed (works as designed) » Closed (won't fix)
Anonymous’s picture

I took your advice, freakalis, and I made my own hook_form_alter() function below:


function list_default_form_alter(&$form, &$form_state, $form_id) {

	// GET CURRENT NODE ID
	if(arg(0) == 'node' && is_numeric(arg(1))) $nid = arg(1); 

	// LOOK FOR WEBFORMS
	if(strpos($form_id, 'webform_client_form') !== FALSE) {

		// CHANGE JOB_POSITION DEFAULT VALUE
		$form['submitted']['job_position']['#default_value'] = $nid;
	}

}

This looks at the current node, finds the selection option from the select list view that is brought in and matches the value to the nid of the current page, and makes the item with the matching value as the default selection. Essentially, there are many job postings on the website, and this defaults the form block at the footer of the page to select the currently viewed job posting as the default in the form to make it easier for the user to apply.

it works great. the webform job_position changes as needed. however, I was wondering if you could help me modify it so that it ONLY gets executed if the current node id is not that of the form's node id. (i.e.- I want it to load on node 190, with form node 192 being loaded as a webform block).