Setting a new record form's hidden field value to a javascript variable?

Hi everybody,

I currently have:

  • A form within my app that creates a new record.
  • The form has 5 fields.
  • Javascript code that defines a javascript variable (let's call the variable "XYZ") each time a new blank form is opened. The code generates a somewhat random alphanumeric serial.
  • An email is sent immediately after the form is submitted with a summary of the submission.

What I need help with:

  • Each time a form is submitted, I'd like the value of a specific field (let's call it "Field 6") for that new record, which is not on the form itself, to be saved as variable "XYZ".
  • Ideally, I do not want Field 6 to be visible at all on the form. If Field 6 does need to be visible on the form, I don't want the user to be able to edit the value to anything other than variable "XYZ."
  • Lastly, I need to make sure that Field 6 does show up in the email summary.

I'm not very well versed in Javascript (think of me as a beginner) and I've tried looking through other posts and the developer guide. I'm quite lost and any help would be greatly appreciated!

Thanks,
Ben

I don't know if I understood you correctly. But you want to send the generated value of the variable xyz in your email.

Simply assign the value of the variable xyz to the input field 6 value. And hide the field6. Use that field6 in your email

JS to assign the value of your variable XYZ to the input field6.

$("#field_6").val(XYZ_variable);

// Hide the field6 input

$('#field_6').hide();

Hi Ben,

I'm doing this a lot, however this won't work in every type of field (for example: does not work on connected fields where you have a drop down selection).

In general you should: create the field in the object, add the field in the form view, hide the field through Javascript and then assign to it your custom value. It will be submitted normally and treated as a form field. Example:

$(document).on('knack-view-render.view_xxx', function(event, view, data) {
var randomTag = "xyzabc";
$('#kn-input-field_6').hide();
$('#kn-input-field_6').val(randomTag);
});

Hope this helps,

Davide