bfuchs
asked on
Find out name of element
Hi Experts,
How do I figure out what is the right name/id for this?
See attached error.
Thanks
Capture.PNG
How do I figure out what is the right name/id for this?
alert('span[id^="cbParamVirtual1_61c45887756bd5LabelCell"]').val); //bf
See attached error.
Thanks
Capture.PNG
ASKER
Hi,
Thanks,
Ben
The real question is - what is it you are trying to do?Trying to figure out the value of that item, at certain point.
Thanks,
Ben
ASKER
Indeed what I really need is to figure out why is the following not getting its expected value.
after executing the below.
See attached.
PS. By solving this you also get to solve the next Q.-:)
Thanks,
Ben
Untitled.png
case when [@field:Status] = 'Completed'
Then (select NotificationEmail from Caregivers where TimeAttendancePIN = '[@authfield:Nurse_UserName]')
Else NULL
End
after executing the below.
$('#customSubmit').click(function(event) {
// set status to complete
$('input[name$="Status"]').val('Completed');
See attached.
PS. By solving this you also get to solve the next Q.-:)
Thanks,
Ben
Untitled.png
Trying to figure out the value of that item, at certain point.There is no value - it is a <span>
$('input[name$="Status"]').val('Completed');
Refers to which HTML exactly - you need to show us that. If you hide the relevant code we can't answer the question.$('#customSubmit').click(function(event) {
// set status to complete
$('input[name$="Status"]').val('Completed');
What happens next - this tells us only part of the story - but the plot thickens after this and without that detail we can only guess.
ASKER
Hi Julian,
Attached the entire JS file, not hiding anything-:)
My main problem is that the calculated field(shown on previous attachment) is not containing the value that's expected.
Thus resulting in the following issue.
Thanks,
Ben
snvn.txt
If you hide the relevant code we can't answer the question.
Attached the entire JS file, not hiding anything-:)
My main problem is that the calculated field(shown on previous attachment) is not containing the value that's expected.
Thus resulting in the following issue.
Thanks,
Ben
snvn.txt
The first thing you need to do is tidy up your code - debugging messy code is a terrible idea.
Secondly, you have a lot going on there - some if statements that run key functionality - which if false will mean your field is not updated - have you checked that you are actually getting inside the if.
Then what does your HTML look like - to figure out what is happening we need to see what the JavaScript is targetting.
I copied your code, disabled the ifs and put a jQuery document ready in place of the DataPageReady you have at the moment and pointed the page at a reflection script. I also created a form with a hidden field named something_Status.
When submitting the form the hidden field was updated to Completed as expected.
Therefore the code is good what is not good is your HTML or your logic around those ifs.
Secondly, you have a lot going on there - some if statements that run key functionality - which if false will mean your field is not updated - have you checked that you are actually getting inside the if.
Then what does your HTML look like - to figure out what is happening we need to see what the JavaScript is targetting.
I copied your code, disabled the ifs and put a jQuery document ready in place of the DataPageReady you have at the moment and pointed the page at a reflection script. I also created a form with a hidden field named something_Status.
When submitting the form the hidden field was updated to Completed as expected.
Therefore the code is good what is not good is your HTML or your logic around those ifs.
ASKER
The first thing you need to do is tidy up your code - debugging messy code is a terrible idea.Agree, however I was not the author and not in that level yet to redesign code done by professionals...
When submitting the form the hidden field was updated to Completed as expected.I know that, as its getting saved as Completed in the database.
The problem is with the calculated field, set as follows
case when [@field:Status] = 'Completed'
Then (select NotificationEmail from Caregivers where TimeAttendancePIN = '[@authfield:Nurse_UserName]')
Else NULL
End
Then this field is being used to setup the email recipient in Caspio (see attached).
Whats ends up happening is that although Status is "Completed", virtual1 which is the email field is null, thus resulting in no email being sent...
Then what does your HTML look like - to figure out what is happening we need to see what the JavaScript is targetting.Attaching that too.
Hope this clarifies...
Thanks,
Ben
Julian.txt
Untitled.png
Untitled1.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Virtual1 is a calculated field, a server side calculated field.
https://howto.caspio.com/datapages/datapage-components/calculated-values/
By virtual that mean created on the flow, not stored anywhere than when the server put it in the page before sending it to your web browser
Calculated fields are calculated BEFORE loading in the browser and are rendered in a <span></span> tag and an hidden field <input type="hidden" value="some calculated value" />
@Julian is right, this is not JavaScript and as this value is ONLY generated by the server you canNOT modify them on client side using input (textbox, textarea, checkbox, radio, dropdown,...button!!!) or using JavaScript code because the server will not care of its value
https://howto.caspio.com/datapages/datapage-components/calculated-values/
By virtual that mean created on the flow, not stored anywhere than when the server put it in the page before sending it to your web browser
Calculated fields are calculated BEFORE loading in the browser and are rendered in a <span></span> tag and an hidden field <input type="hidden" value="some calculated value" />
@Julian is right, this is not JavaScript and as this value is ONLY generated by the server you canNOT modify them on client side using input (textbox, textarea, checkbox, radio, dropdown,...button!!!) or using JavaScript code because the server will not care of its value
ASKER
Hi Experts,
Sorry for the weekend interruption...
So in order to finalize let's focus on what I started...
So how do I have that generating an output, so I can see what value it contains after the script executes the following?
Thanks,
Ben
Sorry for the weekend interruption...
So in order to finalize let's focus on what I started...
To make that statement valid you would have to do this
alert($('span[id^="cbParamVirtual1_6 1c45887756 bd5LabelCe ll"]').val ());
That would not generate an error but it won't give you any output either as <span>'s do not have values
So how do I have that generating an output, so I can see what value it contains after the script executes the following?
$('input[name$="Status"]').val('Completed');
What you are asking sounds like a Caspio specific issue.Exactly, this is what I want to confirm by the above.
Calculated fields are calculated BEFORE loading in the browser...Right, but they do get changed/recalculated when users enter data, so perhaps there is a way to force it to recalculate again at some point...
Thanks,
Ben
So how do I have that generating an output, so I can see what value it contains after the script executes the following?
This is what I said :
and an hidden field <input type="hidden" value="some calculated value" />
Right, but they do get changed/recalculated when users enter data, so perhaps there is a way to force it to recalculate again at some point...
This is what I said :
ONLY generated by the server you canNOT modify them on client side
let's say you change the value using : $('input[name$="Status"]')
what is possible
you want to send an email based on the calculated value, not the the value of the input you just set which is going to be recalculated before displaying the page
I hope I misunderstand the way it work so just ask Caspio if you can use/read this hidden input value to decide if you send or not the email
yes, you change the value of this hidden field but I'm not sure it reflect on Caspio, this is what I really mean by "ONLY generated by the server you canNOT modify them on client side "
ASKER
Hi Leakim,
Now whats about we create a field in source table (not a calculated field), and we update that in JavaScript, just the way we update the Status field thru JavaScript code above, and then use that field as being the email recipient?
Thanks,
Ben
This is what I said :Understood.
ONLY generated by the server you canNOT modify them on client side
let's say you change the value using : $('input[name$="Status"]').val('Comp leted');
what is possible
you want to send an email based on the calculated value
Now whats about we create a field in source table (not a calculated field), and we update that in JavaScript, just the way we update the Status field thru JavaScript code above, and then use that field as being the email recipient?
Thanks,
Ben
ASKER
Hi Experts,
The above approach looks like working-:)
Tested with the following
And I got the email...
Now just need one thing...
How do I assign to it the value of a calculated field (lets say Virtual1 Instead of my email)?
Thanks,
Ben
The above approach looks like working-:)
Tested with the following
$('input[name$="Status"]').val('Completed');
$('input[name$="Caregivers_NotificationEmail"]').val('MyEmailAddress'); //BF
And I got the email...
Now just need one thing...
How do I assign to it the value of a calculated field (lets say Virtual1 Instead of my email)?
Thanks,
Ben
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Experts,
Sorry for the delay in response, was interrupted by some urgent tasks.
@Leakim,
The above suggestion didn't show any value.
Just got response from Caspio how to force recalculation of calculated field as follows.
Will have to test that & let you know.
Thanks,
Ben
Sorry for the delay in response, was interrupted by some urgent tasks.
@Leakim,
The above suggestion didn't show any value.
Just got response from Caspio how to force recalculation of calculated field as follows.
Since the value of “Status” field is modified by JavaScript, we need to programmatically emit the change event for this field so the Calculated Value will be re-evaluated.
The JavaScript line is as follows:
document.querySelector('input[name$= "Status"]' ).dispatch Event(new Event("change"));
Reference:
https://forums.caspio.com/topic/7729-triggering-caspio-rules-programatically/?tab=comments#comment-23586
Will have to test that & let you know.
Thanks,
Ben
ASKER
I have a virtual calculated field as follows.
Any Idea?
Thanks,
Ben
CASE WHEN
--'[@authfield:No_Auto_Emails]' = 'Yes' AND
[@field:Status] = 'Completed'
then
(select NotificationEmail from Caregivers where TimeAttendancePIN = '[@authfield:Nurse_UserName]' )
End
tried the following, no value on the alert. // set status to complete
$('input[name$="Status"]').val('Completed');
document.querySelector('input[name$="Status"]').dispatchEvent(new Event("change"));
var Virtual1_textContent = $("span[id^='cbParamVirtual1']").text();
alert(Virtual1_textContent); // <---- checking with an alert you get the right value
Any Idea?
Thanks,
Ben
ASKER
Hi Experts,
The following code was the ultimate that made the script work. (got it from Caspio)
Thanks,
Ben
The following code was the ultimate that made the script work. (got it from Caspio)
// CASPIO EMAIL : 20190919
var checker = 0;
document.addEventListener('BeforeFormSubmit', function(evt) {
if(checker == 0)
evt.preventDefault();
});
$('#customSubmit').click(function(event) {
// set status to complete
$('input[name$="Status"]').val('Completed');
document.querySelector('input[name$="Status"]').dispatchEvent(new Event("change"));
setTimeout(function(){
checker = 1;
$('#customSubmit').click();
}, 2000);
});
// END CASPIO EMAIL : 20190919
Thanks,
Ben
ASKER
Thanks to both!
val is not a property on alert - nor on anything else and you have too many closing ')'.
In jQuery you have a method .val() and the DOMElement has a property value - but there is no such thing as val
To make that statement valid you would have to do this
Open in new window
That would not generate an error but it won't give you any output either as <span>'s do not have valuesThe real question is - what is it you are trying to do?