You are viewing limited content. For full access, please sign in.

Question

Question

Forms - Populating a read-only field with javascript

asked on June 30, 2016 Show version history

I have read the posts from the community on using Read-Only fields populated with Javascript. From what I understand the only requirement is to remove read only before populating. However in Forms 10 the following code does not work. The field is populated for the user, but not showing with any value once saved to the repository.

  $('.total input').attr('readonly', 'False');
  $('.total input').val(hh + mm);
  $('.total input').attr('readonly', 'True');

We just don't want the users to be able to manually alter the total fields.

0 0

Answer

SELECTED ANSWER
replied on June 30, 2016

If the value isn't getting stored in the repository, that means you probably checked the "read-only" checkbox for the field in the form designer. You need to uncheck that. It not only makes the field read-only, it also adds the disabled attribute to it, which prevents the value from being submitted.

The following should help for your use case:

$(document).on("ready", function() {
    $(".total input").attr("readonly", true);
    $(".total input").val("your value");
});

You can use that in all scenarios where the user shouldn't be able to edit the value, but the value itself should get submitted.

2 0
replied on July 1, 2016

Aha! I misunderstood that read-only was what caused the issue. I just needed to set all fields read-only myself rather than using the built-in checkbox right from the start. Thanks!

2 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.