Drupal 6 textfield form element with ahah attribute - drupal-6

I have a form with a textfield element which when a user starts typing into I want to pre-populate a different element.
I've been using the #ahah attribute which works fine with the event property set to 'keyup' however I lose focus on the textfield element because the moment the 'keyup' event is fired the whole form is rebuilt due to ahah's behaviour.
I tried setting the event property to 'change' and that works nicely however in order for the 'change' event to fire I need to click away from the textfield - so from UI point of view I cannot expect users to click away from field just to get the results to display.
I'm not sure if it's possible to achieve what I want with AHAH which is fine but I'd like to stick with it if possible.
Happy to provide code if required and sorry if it's not clear, quite difficult to explain.
Thanks
Steve

The whole form shouldn't be re-rendered by the browser. That's precisely the idea AHAH, that you can update just part of a form. Make sure to set the "wrapper" attribute (of the #ahah attribute) to the ID (as in: the HTML attribute) of the DOM element that you want Drupal's JS functionality to update asynchronously.
For example:
<?php
function MYMODULE_some_ahah_enabled_form(&$form_state) {
$initial_markup = '<div>' . t('This content will be replaced') . '</div>';
$form['dynamic_thing'] = array(
'#type' => 'markup',
'#prefix' => '<div id="dynamic-thing">', // Set Drupal's AHAH wrapper to this ID
'#suffix' => '</div>',
'#value' => $initial_markup,
);
$form['field_which_will_trigger_ahah_behavior'] = array(
'#type' => 'textfield',
'#ahah' => array(
'path' => 'MYMODULE/path/to/ahah/callback',
'wrapper' => 'dynamic-thing',
'event' => 'keyup',
),
'#default_value' => 'Change me',
);
return $form;
}
/**
* Your menu callback (which is declared in your hook_menu()) which returns only the HTML that will replace the existing markup in $form['dynamic_thing'].
*/
function MYMODULE_ahah_callback() {
$output = '<div>New content for the dynamic thing</div>';
drupal_json(array('status' => TRUE, 'data' => $output));
exit();
}
Your "field_which_will_trigger_ahah_behavior" DOM element in the browser shouldn't lose focus, or be re-rendered in any way, unless there's something else causing some bug.

Related

How to write props properly in styled-components?

I need to change background based on condition if props.src exist. First part works fine, but place where it has props => props.src not getting rendered properly.
Result is:
You only need props.src rather than the function props => props.src in your url:
background: ${props => props.src === "" ? "#eff1f2" : `url(${props.src}) no-repeat center`};
Styled components won’t execute the nested inner function so it just gets stringified.

How to display attached images on single.php file in wordpress

Maybe someone solved this problem sorry if I am asking again this question. I have one post displaying on front page now this post has one feature Image along with other images and gallery.
What I want when user click on post so it will go on single.php to show full post view. I want to display on this single.php view an image and some text as well as a custom gallery images but not the feature image.
how can I achieve this I wrote one code but it did not work.
function displayPostImages() {
global $post; function
$attachments = get_children(array('post_parent' => $post->ID, 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'attachment', 'post_mime_type' => 'image' ));
$image = get_post_thumbnail_id( $post->ID); // featured_image ID
$featured_image = wp_get_attachment_image_src($image);
if ($attachments) { // if there are images attached to posting, start the flexslider markup
foreach ( $attachments as $attachment_id => $attachment ) {
if($attachment->ID != $image && $featured_image ){
$img_source = wp_get_attachment_image_src( $attachment_id, 'full' )[0];
//print_r($img_source);
?>
// here will be HTML to display TOP images text and gallery images.
<?php
}
}
}
}
displayPostImages();
?>
and what is returned your function?
I don`t see "return" or "echo $someresult";
empty or not this array $attachments = get_children....

Add html to menu title in Drupal

I must have missed something. I can't figure out how to add some HTML into the title of the menu.
According to the menu api, I can't add options because I am using MENU_LOCAL_TASK, but then how? There is no say.
For example: if I try to make the title bold:
$items['whatever/tab2'] = array(
'title' => '<b>Tab 2</b>',
'type' => MENU_LOCAL_TASK,
);
This is not working.
You can use 'title callback' => 'example_title_callback',
Function to generate the title; defaults to t(). If you require only the raw string to be output, set this to FALSE.
You could use the Menu HTML module.

show some widgets from view in the left column under menue

I am working on framework yii ,I am using 2-column layout , all content from view are shown in the right column.
I want to show some widgets from view in the left column under menu. how can do it ?
Put in the widgets in the layout. Your view does not stand alone on a page, it usually stays in a layout. In the view (well not really but for the sake of the argument) I do
<?php
$this->breadcrumbs = array(
array('name' => 'Home', 'url' => array('/')),
array('name' => ($this->model->isNewRecord ? 'Create ' : 'Update ') . 'Contact',
);
?>
I can then do in the layout
<?php $this->widget('MyBreadCrumbs', array(
'crumbs' => $this->breadcrumbs,
)); ?>
Read more about the rendering process here: http://www.yiiframework.com/wiki/249/understanding-the-view-rendering-flow/

calling of javascript function on button click in .module file in drupal

I have one button and onclick i want javascript function to be called which contains alert message...............in drupal
i tried many things like...........
1)i created button using
$form['click'] = array(
'#type' => 'button',
'#attributes' => array('onclick' =>_____________),//dnt know what to give for onclick
'#value' => t('click'),
);
2)used drupal_add_js(drupal_get_path('module', 'document').'/eg.js', 'module');in hook_form_alter()
3).js file is as follows
function message()
{
alert("Catch ->This alert box was called");
} -->
want alert message to be displayed on button click.
Kindly help................
Thanks in advance
$form['search_something'] = array(
'#type' => 'button',
'#value' => t('Search'),
'#attributes' => array('onclick' => 'searchsomething()),
);
this is the piece of code to call javascript on button click.
Javascript function
function searchsomething(){
alert("hello");
}

Resources