Automatic calculation in a Drupal CCK field - drupal

I have a three CCK fields: Quantity, Price and Total. I would like to compute Total as a Price * Quantity. Is there any way to achieve this when the user keys in the Price or Quantity the total should be calculated automatically. I also looked upon the computed field module but this works only when I have Price and Quantity and submit the form. I also don't have an idea of applying jQuery inside CCK fields in Drupal.

Use the Computed field module for this.
Although it won't show the value on the node edit form, it will be automatically calculated and can be displayed in a view or in the node display.
Is there a particualr reason you want the total to be displayed on the node edit form? You can add some jQuery to automatically do this but you run the risk of the user changing this field or having JS disabled.

Also there is an alternative to Computed field module for D7.
Math expression fields are dynamically updated via ajax on the entity
form as soon as all necessary fields are populated. If JavaScript is
disabled, the field will be evaluated when the form is submitted. The
result is stored in the database when the form is submitted.
Math Field

Related

Strange search issue occuring after adding field as Alternate search key

I've added an alternate search key to our Vendor pages in FSCM. The search record for the page's component uses a SQL view that I modified, and added in the below custom (PS designated custom field) field (VNDR_FIELD_C30_B) into the view, as well as an additional field in the field list. On the Record Field's properties I set it as an Alternate Search Key.
This field now properly displays on my search page (I changed the label on it for be Employee ID) and I can properly search for a Vendor by inputting a SETID value, along with a value in the custom field. It will bring up the record appropriately, as shown below:
If I click the Return to Search button though, I am brought back to the search page as expected, however if I search for that same vendor again, (or any vendor for that matter) I am only brought to this partially loaded page, and all the other tabs you saw above for the Vendor are missing, as well as the typical bottom navigation/page functions.
I have to click on the page name again from the Breadcrumbs to refresh the page and then I can search for the vendor 1 time again, but on 2nd search I will encounter the same issue again.
Is there a reason this could be caused? Let me know if additional information is needed.

Contact form 7 file field related query

We have required conditional file field that depends on another dropdown field. If dropdown field value YES then file field will show and added required option but if dropdown value NO then file field not show and remove the required option.
We have done the hide show logic in file field but not able to do required option on off. Can anyone please suggest how to do that?
Without the exact website link, it is difficult to explain perfectly. However, from what I understand what you need to do here is to implement a custom validation.
You can refer this link to understand how to implement custom validation.
Basic flow of code:
1. Give ID to the drop down so that you can bind an onchange event with it
2. Bind an onchange event that hide/show the file field
3. Create custom required validation which checks your drop down value and decides whether the other field is required or not
This should do your job... Feel free to ask other questions and post your website uRL and code to get a better answer.

Gravity Forms Multipage Form, dynamically populate from existing form entry based on unique key

I'm working with Gravity Forms (WordPress) on a pair of forms for a school. They have an initial form for applications. Each submission gets assigned a unique five character key to identify it. This is saved in a hidden field. This form has things like name, email, phone, address etc. This form is up and running, working great.
Once a student has been accepted, we now need to have another form that is for registrations. This form will be a multipage form with more detail and various questions about history/parents etc. My thought is that the first page contains a single field that asks for the key assigned to their application. Once this first page is submitted, the form would query the database based on the key and return any info from the original application that applies to the second form. So things like name, email, phone wouldn't have to be re-entered manually.
I'm starting down the road of dynamic population and running into some trouble. It appears things operate differently on multi-page forms, and depending on whether you're using AJAX or not. Has anyone had experience doing this kind of key lookup for form population? I could do this in vanilla PHP/MySQL without a problem, but the Gravity Forms stuff has me stumped.
Your question is not clear enough and is left open for interpretation. However, since I ran into problems with multi-page gravitiy forms as well, and could find very little help online, here is my experience.
If you go from one page to the next, you can access field values from previous pages using rgpost("input_" . YOUR_FIELD_ID);. Checkbox collections are accessed by "input_".FIELD_ID."_".OPTION_INDEX. Dynamically filled dropdowns seemed to get reset in my experience. If this happens to you, before moving to the next page, you can copy any values from these fields into hidden fields, and read from the hidden fields.
Fields that already have a default value (field->defaultValue) are NOT updated even though the appropriate hooks are triggered. E.g: add_filter('gform_field_value_my_field', 'populate_your_field'). A dump of the value you return in populate_your_field will show a different value than when you inspect my_field, which is supposed to receive this value. my_field will retain the first value it received and wont change anymore.
This is a problem when your fields depend on input of fields from previous pages, and users go back and forth changing those. Your dependend fields wont update on any hook. I've tested extensively with gform_field_value, gform_pre_render, gform_field_validation and gform_post_paging.
I found one solution: echo a hidden div with data attributes in the gform_pre_render hook, and populate the fields through javascript.
add_filter('gform_pre_render', 'dynamic_population', 10, 1);
function dynamic_population($form) {
echo "<div id='my_data' style='display:none' data-myjsonarray='.json_encode(my_json_array).'></div>";
}
In your gravity form, you can create a html field and add javascript in there.
<script>
window.onload = function() {
//custom function that fills given gform dropdown with given array
fill_dropdown(
jQuery('#input_1_1'),
jQuery('#my_data').data('myjsonarray')
);
}
</script>
Hope this somehow helps someone.
Gravity Forms Populate Anything can handle this really well.
Add a field to your form where the user would enter their reference number.
Configure a field to be populated with the entry data based on the provided reference ID where it matches an entry that has the same reference ID:

Editable field action in sonata list view

I have a list view in sonata admin. I want to edit integer field directly in list view. New data for this field must change other fields in my entity. How can I add action function to this editable field in which I may do some actions with other fields depending on entering integer value?
Please check documentation: https://sonata-project.org/bundles/admin/master/doc/cookbook/recipe_custom_action.html
Basically, what you need is a custom route and and a controller, same way as you handle any page/request. Than you can do any logic you like making requests to this routes (even with AJAX). Documentation will help you the best with this.
And to add an "editable field" or a link or a button in List view, just create custom template piece: https://sonata-project.org/bundles/admin/master/doc/reference/templates.html

programmatically fill in all the required fields in a webform, then submit manually

I want to programmatically fill in all the required fields in the webform at
http://www.whitehouse.gov/contact/submit-questions-and-comments
except for the final challenge question (which must be answered manually and then the form will be submitted manually). Is this possible?
Alter the form before it's rendered:
https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_form_alter/7
Set different default value for that field.

Resources