Hey there, I'll preface this by saying I'm a total newb when it comes to coding and basically am learning as I go along.
I've been trying to set up two forms, one basic form where one can only enter base parameters, and one advanced form for more detailed parameters, and said advanced form is supposed to be accessible via a checkbox - if you check the box, the advanced form opens, and if you uncheck it, an additional flag will trigger for the script to disregard the data in the advanced form.
function DataForm_tpAdvanced_OnChange(Sender) { if(UserForms.DataForm.tpAdvanced.Checked) UserForms.AdvancedForm.Show(); }
Either way, here's the problem: No matter if the box is checked or unchecked, the Advanced Form will always show. I've changed the script to display in the log whether the box returns true or false, and it returned true and false respectively as expected. However, the if-statement simply ignores it and always returns checked, regardless of the actual state of the box.
Thanks in advance
Solved! Go to Solution.
Everyone who gave me your helpful responses, I solved it by realizing I was very stupid and looking at JScript and not JavaScript - I adjusted the code to be
function DataForm_tpAdvanced_OnChange(Sender) { if(UserForms.DataForm.tpAdvanced.Checked == True) UserForms.AdvancedForm.Show(); }
and it works like a charm now! Thanks for all the advice and sorry for possibly wasting anyone's time!
Hi,
Did you try to use the solutions from these docs?
and see if the object you're using is on the "on_change" list.
"
The event applies to the following components:
TcxButtonEdit, TcxCalcEdit, TcxCheckBox, TcxComboBox, TcxCurrencyEdit, TcxDateEdit, TcxMemo, TcxMRUEdit, TcxRadioGroup, TcxSpinEdit, TcxTextEdit, TcxTimeEdit
"
https://support.smartbear.com/testcomplete/docs/reference/user-forms/events/onchange.html
Thanks for your quick response! From what I understood, the "Determining a Check Box's State" article only applied to checkboxes on the site I am testing, and not to user forms.
The object in question is a TcxCheckBox, and I basically just copied the function from the sample User Forms.
I think @Wamboo is right that you're going to want to use the "OnChange" event for the checkbox and, in that event, check the state of the checkbox to determine activity.
But - and correct me if I'm wrong, I'm really really new to this whole stuff - isn't that what I already showed in my code snipped in the original post?
Yes, the code is there for an OnChange event, but I think it's an event on the form, not on the checkbox itself.
I just tested a few other alternatives, and I came to the conclusion that the "Checked"-call returns the correct case, but if used in an if-statement always defaults to true.
I wrote the following little script:
function AdvancedForm_apTestButton_OnClick(Sender) { if (UserForms.AdvancedForm.apAdvancedResults.Checked) ShowMessage("1") else ShowMessage("2"); Log.Message("Checked = " + aqConvert.VarToStr(UserForms.AdvancedForm.apAdvancedResults.Checked)); }
No matter whether the checkbox is checked or unchecked, it always shows "1", however, the state of the checkbox is successfully and correctly logged.
Hi,
Is this check-box two- or three-states one? (I.e. can it be 'greyed'?)
What if you try
if (aqConvert.VarToBool(UserForms.AdvancedForm.apAdvancedResults.Checked))?
Everyone who gave me your helpful responses, I solved it by realizing I was very stupid and looking at JScript and not JavaScript - I adjusted the code to be
function DataForm_tpAdvanced_OnChange(Sender) { if(UserForms.DataForm.tpAdvanced.Checked == True) UserForms.AdvancedForm.Show(); }
and it works like a charm now! Thanks for all the advice and sorry for possibly wasting anyone's time!
Subject | Author | Latest Post |
---|---|---|