Closed (fixed)
Project:
Drupal core
Version:
7.2
Component:
ajax system
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
26 Jun 2011 at 00:18 UTC
Updated:
4 Jan 2014 at 00:53 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
rfayI assume this is a support request for webform module, so changing to webform queue.
Comment #2
quicksketchThis is not possible with Webform module. See the similar request over in #354381: Webform Submission with "add another" text field.
Comment #3
dtksmsl commentedI am trying to do this by using an array. The ajax callback has to update a value in a text field. But my problem is that I am not able to change a value in a text field from inside ajax callback function.
Comment #4
quicksketchFirst of all, are you actually using Webform module at all? If this is a general Form API question, this request was probably miscategorized. If you are using Webform module, I don't provide support on custom coding in the issue queue.
Comment #5
dtksmsl commentedI am using the form API. How do I correctly categorize this?
Comment #6
quicksketchSo looks like you had it correctly categorized to begin with, the mention of a "table webform" threw everyone off because "webform" is a specific module in Drupal.
There are generally two ways to do what you're asking. First you could replace the entire table in the form but add an "ajax-new-content" class to the last row in the table to make the new table row fade in after the AJAX request. Even though it looks like modules are simply adding a new row to the table, most of them use this approach to add a new row to a table. Examples of this include File upload fields and all the "Add another item" buttons provided by Field module.
The other way you can do this is by sending back and AJAX command for append on the tbody tag (http://api.drupal.org/api/drupal/includes--ajax.inc/function/ajax_comman...) and then restripe the table with the restripe command (http://api.drupal.org/api/drupal/includes--ajax.inc/function/ajax_comman...).
Comment #7
dtksmsl commentedAppend would not work because in a row I have two textfields that get populated after the ajax callback. So the ajax callback would replace the current row and also append a fresh new row just below it. I am trying to use a counter which has to be updated from inside the ajax callback function. But after trying for hours I couldn't update the counter from inside the callback function. I tried drupal_set_value(), also tried global variables, I tried, form_state[][][] but to no avail.
The row looks like in this image attached. The disabled fields are actually to be replaced by ajax callback.
Comment #8
quicksketchIn which case you should also put a #submit operation on your form to set the necessary values. The #ajax callback you have specified will happen after the #submit handler. So the #submit handler sets all the values, then the #ajax callback just returns the new data. I suggest looking at http://api.drupal.org/poll_form or the Examples module to learn how to do AJAX properly with Forms API.
Comment #9
webankit commentedHow to achieve this via ajax-new-content class?
I added this class to my last row.
(I am using $form_state['count'] for my last row max delta)
But what next...
Do I need to include some css file?
My table become normal div after ajax, as if theme function didn't run.
Comment #10
dddave commentedThe OP was fixed with quicksketch's remarks. #9 is not relevant to core. If you cannot solve this by reading up docs you should better ask in IRC for help.