Why adding form element in ajax callback doesn't work (ref. FormAPI-52)

No replies
relaxpor
Offline
Last seen: 9 years 4 weeks ago
Joined: 2013-05-07

Reference to Drupal 7 Dev Core > Form API > Chapter 52: Using the #ajax
(Link: https://buildamodule.com/video/drupal-7-development-core-concepts-how-to...)

The tutorial trying to implement ajax for adding checkbox after select the OS select field.

I tried to modify this a little by move the code block of following...

if (isset($form_state['values']['os'])) { // Fixed this line, was throwing an error in the original video code.
$form['computer_stats']['os_verify']['#type'] = 'checkbox';
$form['computer_stats']['os_verify']['#title'] = t('Are you sure you are using @os?', array('@os' => $form_state['values']['os']));
}

into the function input_os_verify_ajax_callback($form, $form_state)
before return them back.

It should work but it doesn't.

I wonder why it doesn't work? Since this method also return the $form element to the callback
and i think this way it make more sense.

Please help. Thank you.

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.