There is nothing native or Action-based that can do these calculations for you – and if you think about it, that’s as it should be, since there’s no way to tell what sort of calculations you might need.
If you want a live updating “estimate” form, (air-quotes because I want you to remember that anything that happens on the browser is inherently un-trustworthy) then you can do that with JavaScript, and Protaculous will give you easy hooks into the fields. Basic rules:
-
Make sure that you give your form fields proper names. The content of the Title field in the left-most Inspector tab is meaningless, it’s just Freeway’s internal name for the field. The third tab from the left contains the Name field, which is where the actual name attribute for the form (which a form handler or script will need) is generated. A proper name is like an HTML ID: must begin with a letter or an underscore, should only contain letters, numbers, hyphens, or underscores. No spaces, no other punctuation of any kind. If you stick to a pattern of replacing spaces in the human-readable name with underscores, you can automatically replace them later: My Form Field becomes my_form_field, and then you can substitute an underscore followed by a letter with a space followed by a the capitalized form of that letter automagically.
-
Make sure that you apply the FormFix Action to the page. This will clean up some foibles in Freeway’s form element code. It will apply IDs to each field, fix a nagging problem with select (picking list) fields, and I think it does some voodoo with radio buttons, although I can’t recall at the moment.
If you’ve done these things, then you can get a handle on the form element you want to add to another like this (in Protaculous):
$('calculate_button').observe('click', function(evt){
var one = parseInt($F('item_one'), 10);
var two = parseInt($F('item_two'), 10);
//your math here
var total = (one + two * 42) / 100;
$('output_area').update(total);
});
That’s an extremely naive bit of code, doesn’t check anything for proper values or anything, but it shows off a few Prototype features. $F() is a shortcut for Element.getValue(), and it wants the ID of the field you are reading as its one argument. update() takes its input and inserts it into the item it’s chained from. It can take anything – plain text or HTML – as its input. If the latter, the actual DOM element will be created and inserted, not the text that describes that element.
Now you can do any of this on the server as well, and if you need to trust the input, you should do that. Many applications I have worked on use JavaScript on the client to provide a fast user response, but then duplicate the entire thing on the server where the variables can’t be fiddled with.
Walter
On Jun 9, 2012, at 1:45 AM, Brian Yun wrote:
Dave - Personally, I agree with your 2c, but it’s what he’s asking for. I revisited the link, and I think that he would be fine if the total showed up after they submitted, as long as the information was captured and sent to him. I’m still confused on how you get the form to do the calculations with FW. I’ve looked at every action I can and don’t see anything that would calculate any values. Did you write the function and used Protaculous to add the code to the page or is there something in FW that does calculations.
Brian
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options