I need to create a simple form which asks two values from the user, and when she submits the form shows a value calculated based on those values.
For example, user could be shown something like this:
1st number:
2nd number:
Result:
Calculate!
The only editable fields are 1st and 2nd number. After giving the numbers and clicking Calculate!, she sees the following page:
1st number: 15
2nd number: 20
Result: 35
Calculate!
She can now modify the numbers and reclick Calculate! It is OK to submit and reload the page, the values don't need to be updated in-place.
Do I have to do this using JavaScript injection, or is there another way?
Take a look at Computed Field module.
You don't have to do something like this with JavaScript, but that would be the quickest and easiest solution. Especially since you have jQuery available. You don't even have to let users click calculate.
example code:
$("#input_1, #input_2").change(function(){
$("#result").text(parseInt($("#input_1").val(), 10) + parseInt($("#input_2").val(), 10));
});
given two input fields with id input_1 and input_2 and a span/div etc. to display the result with id result the above code automatically calculate the two values whenever something is new is entered into them.
I see here several possible options:
1) You can even create a simple form and, using JavaScript, calculate the data entered in the fields, you can even use simple jQuery, as already suggested in one of the answers.
2) Search for ready-made modules on the official Drupal website, for example:
WebForm Calculator
Simple Calculator
True, everything will probably have to be refined, but I think it will not take many lines of code.
3) Use the builder uCalc - it does not require programming and all actions occur in the visual editor. You just throw the necessary widgets into the form and do the calculation for the values you need. Very useful thing and saves time.
4) There are a few more websites that can be downloaded ready-made scripts of such calculators, but they will need to be seriously developed.
Related
Update: With the help of the answerer below I figured out how to do this. Basically I used a WP Query to get users and their user metadata and I sorted and placed the data in a for each loop in a table.
I'm new to PHP and I need some help. Basically I want to create a leaderboard with different user data. I want to display it in an html table.
This is kinda what i want:
Username GamiPress Points Time since last login
And I want the table to be populated with these data amongst others automatically. I want two versions one that is sorted with the 15 users who have the most points and one that sorts on the 15 users that logged in last.
Can someone point me to the right place on how I can best implement this?
I basically want to create the GamiPress Leaderboard add-on that I, unfortunately, can't afford, but with some extra fields.
There are multiple steps to do if you want to achieve this:
1) Add meta field to your users, so you can store the points. For example you can use "Advanced Custom Fields" plugin for this.
2) Write a function for adding points to this field. Define when this function will be fired.
3) Query the users ordered by that meta value and display it (get_users($args) might be useful).
4) For the Last-Login value you can use a plugin (google Wordpress Last Login) and write another Query and order results by that meta field. You can also write this by your own, here is a link I found: https://www.wpbeginner.com/plugins/how-to-show-users-last-login-date-in-wordpress/
I don't know if this is what you were looking for.
Or did you want to see an example code how you use a wp query and display data in html table?
For this report, I need one field (Sales Code) to only show if it has been updated. Periodically they change Sales code and I want a report to show the prior code along side the new code when it changes. Along with its part number and so on.
I was wondering the best way to go about tackling this request.
I tried to do _add_days -1 and compare the Sales code --> Sales code1. I dont think that will give me what I am looking for.
For example Sales code changes from AA --> AB.
I want to see New CODE OLD Code Part Number and so on...
AB AB 12345
The pattern you are encountering is called a slowly changing dimension.
Here's a wee free primer.
https://www.kimballgroup.com/2013/02/design-tip-152-slowly-changing-dimension-types-0-4-5-6-7/
You don't mention the structure of the data you're working with so it would be quite difficult for me to say what type you have other than the fact that you're trying to track historical data and seem to have it captured somehow rules out type 0.
Because of that, I can't come down from Mount Sinai with the solution but this can help you start to think through the problem.
In Framework manager have the modeler design the fields for SalesCode and SalesCode1
To only show if there was a change
Add a detail filter:
SalesCode <> SalesCode1
To control the context of time, have a separate filter like:
[Sales Date] between ?FromDate? and ?ToDate?
I have a little appliation that shows MySQL data in web browser ListGrid. It has 14 columns.
I would like to upgrade it so the user could add query parameters.
For this job the best I could imagine is the grid.setShowFilterEditor() that put text boxes above the column headers and will live together with the column header when moved or resized.
I planned to use the filter button FilterEditorSubmitHandler() to get the filter values and run the query.
Unfortunately, I can not find any solution to get the text from a certain filter box eg. the value that was written by the user into the box above Column_#1. Is there any way to do that or this FilterEditor grown together with the DataSources object, and not available for any other data binding?
Something like this, but without using DataSource:
http://www.smartclient.com/smartgwt/showcase/#grid_sortfilter_disable_filter
As per my knowledge, filter editor works on com.smartgwt.client.data.DataSource only.
If you want to have filterEditor in ListGrid, you have to use DataSource or go for some custom implementation.
It is easy to calculate a sum, an average or a maximum accross set of fields using built-in xpath functions.
But is it possible to calculate a product?
Assuming I have repeating elements like
<my:table>
<my:row>
<my:value>10</my:value>
</my:row>
<my:row>
<my:value>20</my:value>
</my:row>
<my:row>
<my:value>30</my:value>
<my:row>
</my:table>
(the number of my:rows may vary).
i need to have a formula multiplying all my:values: 10*20*30 (and working with any number of rows).
Any ideas?
Please do not suggest code solutions, I need this for a restricted form.
Using conditional hack described here, I finally assembled the solution.
Inside my:row, create a running product field my:valueCumul, populated using a formula to refer to previous row, and leveraging the conditional hack to override NaN for the first row:
../my:value *
concat(
(count(../preceding-sibling::my:row[1]) = 0) * 1,
substring(../preceding-sibling::my:row[1]/my:valueCumul, 1, (count(../preceding-sibling::my:row[1]) = 1) * string-length(../preceding-sibling::my:row[1]/my:valueCumul))
)
Outside the table you can easily refer to my:valueCumul in the last row to get total product:
../my:row[count(../my:row)]/my:valueCumul
The nice features of this solution are:
Works in a browser form in any sharepoint environment
Is not impacted by "16 calculations" threshold
The formula is robust to row removal and shifts
You can't with the built in functions in InfoPath.
However, don't write off a code solution so fast. If you only access data elements in the form itself (nothing EXTERNAL) then you can leave the form as restricted security and the code will run with no problems - the user doesn't know the difference.
It is fairly trivial to attach to the right event, grab the nodes, and loop through them while multiplying. You don't even have to use managed code - use one of the script options. Comment back (or update your original post) if you run into any troubles and we can help resolve them.
I have a form in which I am attaching a workflow to. The form has a number that will be auto-generated. For example the first number will be 1, the next time the form is opened the number should be 2, so on and so forth. The issue I am having is: in the Default Value under the Text Box Properties I have the Value as: count(mynumber QuoteNumber) +1. When the form is generated the first and only number is 2 the number begins at 2 and never increases. Can someone help me with this or explain what I may be doing wrong? Thank You. I'm not using visual studio.
Rachel: I have fought with this problem since InfoPath 2007. Here is how I do it.
Since you say you are attaching a workflow, I assume you are using the from in SharePoint.
1 - create your form library in SharePoint
2 - use InfoPath to design the form. When you publish the form to SP, make sure you promote AT LEAST the ID field you want to auto-inc. (I usually promote every field in my forms, 'cause I like to use them like SP lists.)
3 - In SP, create one new form and manually set the ID field to the starting number for your form series.
4 - return to InfoPath designer and re-open your form template.
5 - create a new data source to receive data from your SP form library and specify your form library as the source, and the ID field as a data element. Name the data source something like “ID Lookup”.
6 - open the properties of the field you want to auto-inc on your form and, in the default value box, select function, then choose the MAX function.
And add “+1” after the function to increment by 1.
Now, double-click in the field are of the Max function. You will see a dialog showing your form fields. Notice the drop-down at the top of the dialog – here you can choose the data source (notice I named mine “sales Contracts” in this example). If you select the data source you created in step 5, you will see a dialog showing you a couple of data branches.
Expand the ‘dataFields’ branch until you see the field you want to auto-inc. Click on this.
Your formula dialog will look something like:
max(ID_X0020) + 1
With your field name instead of the 'ID' in the Max function – the function will now return the Maximum value of the field IN THE FORM LIBRARY, plus 1.
Save the form in InfoPath and try previewing it. You will probably get a security warning – your InfoPath form is grabbing data from your SharePoint library on the fly. You may even get asked to re-enter your password (I usually do). When the new, blank form is displayed in InfoPath preview, you should see you ID field filled in with a value one greater that the number in that field of your SP library.
There is one huge Gothca with this method - if users re-open a completed form to edit it, the formula will probably try to replace the ID number. If your users don't edit the forms after they are submitted, the this will work for you.
Hope this makes sense.
You aren't doing anything wrong - you just have to change how you think about "forms" a bit. Remember a form is just like a word document template. Suppose you save a word document on your hard drive with a blank spot to fill in your name. Later you open the template, type your name, and save a copy as V1.doc. When you go back and open the template again - your name is not there because it was saved in V1.doc. Everytime you open the template you start again from scratch.
Infopath forms that you design and that the user fills out are templates (.xsn files). When the user fills it out and saves it they are really saving a copy which is only data (.xml files). The .xsn template doesn't change when users interact with it.
So to answer your question - there is no way directly in InfoPath to cleanly keep track of an auto incrementing ID. You will need to tap into some code (webservice, sharepoint, etc) to do that. You could also consider making the ID a GUID (which infopath does support) but it won't be auto incrementing and it won't look "clean" if it has to be displayed/used by real people.