This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 3
Feature Request: Custom javascript hooks on a per form basis
Started 12 years ago by nationjob | 10 posts |
-
We would REALLY like to be able to push our own javascript into each form. This would help us GREATLY in doing odd things with the form client side.
Posted 12 years ago # -
This might make sense in the template part instead of the form itself. That way we could set up specific templates with the common code we want,
Posted 12 years ago # -
I agree that we should have a way to implement custom javascript for each form. We're putting this into our todo list.
MachForm Founder
Posted 12 years ago # -
Any progress on this? I'd love custom javascript as I said in my email;)
Posted 11 years ago # -
Hi -- just to let you know, we've had some success placing Javascript directly in the form description field. Not ideal -- would be better to add it to the <head> section, but it did let us modify some behaviours on the fly.
Cheers
RodPosted 11 years ago # -
I approached this a different way, and it seems to work so far.
I have included a custom.js file in the <head>, which for me is around line 5020 in view-functions.php using MachForm 3.5.
<script type="text/javascript" src="{$machform_Path}custom.js"></script>
This JavaScript file is therefore called by all forms and can target individual forms by checking whether the form ID exists. If it does, it runs the function for that form. You can have multiple form IDs in separate if statements; therefore, this can work as a custom JavaScript for as many forms as you would like. The change function below adds up six number and displays it in a disabled input (element_81).
$(document).ready(function () { var one, two, three, four, five, six, total; // JavaScript for form_10942 if ($('#form_10942').length) { $('#element_81').prop('disabled', true); $(document).change(function () { one = $('#element_75').val(); two = $('#element_76').val(); three = $('#element_77').val(); four = $('#element_78').val(); five = $('#element_79').val(); six = $('#element_80').val(); total = parseFloat(one) + parseFloat(two) + parseFloat(three) + parseFloat(four) + parseFloat(five) + parseFloat(six); $('#element_81').val(parseFloat(total).toFixed(2)); }); } if($'#form_10943').length { // Do something for form_10943 } });
Posted 11 years ago # -
Just realized, in the second if statement, I did not close the clause. Please use it like so:
if($'#form_10943').length) { // Do something for form_10943 }
Posted 11 years ago # -
Are there any updates on this?
Posted 10 years ago # -
Bumping - any updates?
Posted 10 years ago # -
Sorry it took so long for this to get implemented. We've completed this for v4.2. We expect to release v4.2 before the end of this month.
MachForm Founder
Posted 10 years ago #
Reply
You must log in to post.