Jump to content
  • 0

another question about Passing Data From A Virtual Field To A Non-Virtual Field


innov2e
 Share

Question

I have a table with 3 fields:
ID (Autonumber and unique), FieldAA (Text 255)  and FieldBB (Text 255).
My web form to update records shows Virtual1 getting its value as External Parameter  [@Param1], then FieldAA as Text Field, FieldBB and ID as Display Only.  I wish to set FieldAA with the value of Virtual1 when submit pressed.

So looking into this post https://forums.caspio.com/topic/4983-passing-data-from-a-virtual-field-to-a-non-virtual-field/  I added at bottom an html block,  disabled HTML editor and   added this code

<SCRIPT LANGUAGE="JavaScript">
function concatenate()
{
var x = document.getElementsByName('cbParamVirtual1').value;
document.getElementById('EditRecordFieldAA').value = x;
}

document.getElementById('caspioform').onsubmit=concatenate;
</script>

Using the web form I get correctly both values of FieldAA and FieldBB and Virtual1 shows the parameter value I passed, but when I click submit FieldAA or edited records remains unchanged. 

Where I am lost? Inspecting page all seems correct but my feeling is that my concatenate function is never triggered. I tryed also to add a console.log("I was here...") just before the end of the function and nothing appear on console.  I am doing my first app and I am shure that my newbie status make me blind to something, do you have any hints?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Hello @innov2e,

This should work with document.getElementsByName.

Please note that it returns not a single value, but the NodeList Collection of elements, so to get the value you need to use [0] index:

document.getElementsByName('cbParamVirtual1')[0].value

So, you may try this code: 

<script>
document.addEventListener('BeforeFormSubmit', function(event) {
	let virtualField = document.getElementsByName('cbParamVirtual1');
	document.querySelector('#EditRecordFieldAA').value = virtualField[0].value;
});
</script>

 

Link to comment
Share on other sites

  • 0

Hello @innov2e,

Please try to use this code in the Footer section of the DataPage.

Do not forget to disable the HTML editor before pasting the code.

<script>
document.addEventListener('BeforeFormSubmit', function(event) {
	let virtualField = document.querySelector("#cbParamVirtual1");
	document.querySelector('#EditRecordFieldAA').value = virtualField.value;
});
</script>

Please update this thread in case you have further questions. 

Link to comment
Share on other sites

  • 0

Hello again @innov2e,

This should work for the Details page as well, and you may refer to the editable fields as "EditRecordFIELDNAME" (more details can be found in this post https://forums.caspio.com/topic/4377-js-guide-caspio-form-elements/)

Single Record Update form and Details page display 1 record per time and you may set the fields as editable on both of them.  

If you pass some value as a parameter, I believe you need to create separate Results and Details https://howto.caspio.com/tech-tips-and-articles/tech-parameters/results-and-details-on-two-separate-web-pages/

You may provide with more details about the Details page if needed, so I can test it from my side. 

 

 

Link to comment
Share on other sites

  • 0

Hi  @CoopperBackpack

the second data page is a tabular report with all three fields both in search, results and details definitions. From my tests in not necessary to have separate Results and Details datapages, because the Virtual1 Field defined into the details page and requiring parameter work as expected: when I preview the report page parameter is asked and is passed to every record i select where it is used.

Now I wish to avoid users to change this value  making the Virtual1 Field Display only, but:

- If I set Virtual1 as Text it results as 

<input type="text" maxlength="64000" name="cbParamVirtual1" id="cbParamVirtual1" value="Valery" class="cbFormTextField" size="25">

 with the id parameter. I suppose it allow to be addressed by the querySelector

-  If I set Virtual1 as Display Only it results as

<input type="hidden" name="cbParamVirtual1" value="Valery">

without the id parameter and I have no idea how to get it. I tried from console  with getElementsByName but with no results.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...