Need to fire an event after entering text in a text_field - watir-webdriver

I have a need so as to enter some text in a text field and then tabout of the text field so that the value in the text field gets validated by a service. I tried to click some other elements in the page but that apparently did not trigger an event to call the service. Is there a workaround in this case? Thank you!
class MyPage
include PageObject
text_field(:txtinput, :id => 'textV1')
span(:for,:id => 'For' )
def enter_my_info(data)
self.txtinput = data
self.for_element.click # click someother element in the page
end
end

That type of behaviour often is often triggered by an 'onblur' event. You can manually trigger this use the page object element's fire_event method.
def enter_my_info(data)
self.txtinput = data
self.txtinput_element.fire_event('onblur')
end
If that does not work, you could try mimicking the user behaviour and input a tab character. You can send special keys via the send_keys method.
def enter_my_info(data)
self.txtinput = data
self.txtinput_element.send_keys(:tab)
end

Have you tried sending the tab key on the element
http://watirwebdriver.com/sending-special-keys/

I've ended up just clicking parent:
t = b.text_field(class: 'uploadFileTitle', tracknum: index.to_s)
t.set(track.name)
t.parent.click // loses focus here

Related

Pressing Enter on a date input in Cypress

I have an app with some input fields that I'm trying to automate. The gist of these fields is that I should be able to double click a field, type in a new value, then press Enter to submit that value, which sends a PUT request and also closes the input field. This works for any input type except date.
So far I've tried:
Using cy.type('{enter}'). This gives Typing into a date input with cy.type() requires a valid date in the format 'yyyy-MM-dd'. You passed: {enter}
Using cy.trigger() to send out a keydown event for the enter key. This works, as in it closes the input field successfully but it somehow doesn't send the PUT request.
Pressing enter on the parent Element. Same as using cy.trigger()
Strangely enough, manually opening the input field myself, typing a date and pressing enter will send the request just fine. It seems to me like there's some issue with programmatically pressing enter to submit the field without Cypress interpreting this as my attempt to actually type an invalid character into the date field. The docs do specifically say that no special characters are allowed in a date field.
Can't post any code as this is corporate.
I have tried to let it work, but it simply can't be done at the moment. Something like this should work:
it.only('test', function () {
cy.visit('https://www.html5tutorial.info/html5-date.php')
cy.get('input')
.type('2009-12-12')
.type('{enter}')
})
But it doesn't so I started to dig into the pile of issues and found this one:
https://github.com/cypress-io/cypress/issues/3405 . It is about a different input type, but I believe it is related to your problem.
Unfortunately this problem is still present in Cypress 9.5. One possible work-around is to directly trigger the Javascript keyup or keydown event that you are listening for.
cy.get('input')
.type('2020-01-01T12:00')
.trigger('keydown', {
key: 'Enter',
});
This works for me, but as you pointed out might not in all situations. It depends entirely on how your app is listening for Enter in the first place and on which element.
Another possible option is to call .submit() on the form that wraps the input. If you're testing a component, you could create your own wrapper component that contains a form in order to trigger the submit.
You should remove 'date' attribute like below:
cy.get('input').invoke('removeAttr','type').type('2009-12-12{enter}');
I used something like that in my code, and it worked properly
cy.get('get-your-input').invoke('removeAttr', 'type')type('2022-12-01{enter}').trigger('change');
cy.get('get-your-input').invoke('attr', 'value', '2022-12-01').trigger('change');
cy.get('get-your-input').invoke('attr', 'type', 'date');
Please add date plus enter keystroke in the type: cy.get("#date").type("02-02-2022{enter}");

MS Access: Enter a specific text in a form using command button from another form

I would like to ask for your help on the following issue in MS Access.
I had created a form "CustomerListF", filled with command buttons for each client. For each button, I had created the following code:
Private Sub cmd_outlets_ABC_Click()
DoCmd.OpenForm "OrderFormF"
Forms!OrderFormF!Outlets = "ABC"
End Sub
The button would then open another form "OrderFormF" and enter "ABC" in the textbox named "Outlets". However, I realized the second line of code (Forms!OrderFormF!Outlets = "ABC") would always create a phantom record in my subform, which is located in "OrderFormF", and this record would travel to other clients' forms. This phantom record is usually created when the commandbutton is clicked twice (double clicks or subsequent clicks). It is a headache when the record starts to shift around.
enter image description here
I would like to seek your advice for vba code to edit the second line of code.
Thank you.
This approach for filling the field in opened form is not good. OrderFormF initialization and second line of your code with assigning value to the field may be executed in different sequence, they are not synchronized.
In order to avoid this, you should pass the argument to OrderFormF by another way. I would recommend to use OpenArgs parameter:
DoCmd.OpenForm "OrderFormF",,,,,,"ABC"
And then in Load event of OrderFormF assign the value to textbox:
Me.Outlets = Me.OpenArgs
In this case the "ABC" value will be assigned to first row in the form or to new record, if form is empty. Before assigning you can select the row if you need to assign value not to the first row. Also this way will protect you against double click on button, Load event executed only once during first form opening

Disable a form if the other is updatable

I'm using page fragments to create a view and in the same page I have two forms to view / update specific information.
What I want know if it's possible to disable one form (or button, since it's the way I use to change from readable to updatable) based on if the other is in updatable mode.
Simplifying I have form A and B, both in the same page as readable. When I select A to update I want B to disable the option to edit until A is back to read mode, and the same to B form.
Can anyone help me?
---Update
Flows
A
B
In each fragment (view) I have a button that as an action to the fragment (edit)
What I need is to disable the button from B.view when A button is pressed and vice versa
If the forms are part of separate taskflows and these taskflows are used on the page as regions, then you will need to enable inter-region communication, so that an action in one region can affect the data and behavior of other region:
http://www.oracle.com/technetwork/developer-tools/adf/adfregioninteraction-155145.html
For your use case, contextual events can serve the purpose:
http://rohanwalia.blogspot.com/2013/07/contextual-events-basic-step-by-step.html
http://www.awasthiashish.com/2013/05/using-contextual-event-in-oracle-adf.html
https://blogs.oracle.com/raghuyadav/entry/refresh_bounded_taskflows_acro
To implement your case, follow the tutorials provided above with following changes:
Pass a boolean value in the customPayLoad of event
<event name="DisableButtonEvent" customPayLoad="${'true'}"/>
In the event handler method assign the payLoad value to a scope variable:
public void handleDisableButtonEvent(String payLoad) {
AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
Map pageFlowScope = adfFacesContext.getPageFlowScope();
pageFlowScope.put("disableButton", payLoad);
}
Use the scope variable for disabled property of button on second region
<af:commandButton text="EditButoonB" id="cb1"
disabled="#{pageFlowScope.disableButton ne null? pageFlowScope.disableButton : false}"/>

ACCESS: Ticking checkbox on form if a value beginning with "(REF)" is selected from combobox

I am trying to tick a check box on a form when I select one of many combobox values that begins with (REF) - this is code that stands for Referral closure.
this is what I've done..it's not working
Private Sub ReasonForInappriopriateReferral_AfterUpdate()
If Me.RsnForInappropriateRef.Value Like "(REF)*" Then
Me.Check66 = True
End If
End Sub
Please help, I was previously trying to conditional format a label to a different colour if the closure reason was a Referral closure, but couldn't do that either and think it could be down to the IF Like command.
I added two controls exactly as you indicated. I populated my combo by setting the Row Source Type to a Value List, and the Row Source to "Blah Blah";"(REF) - Jackson";"Two Times";"(REF) - Tyson"
I put this in the Click event of a button:
If Me.RsnForInappropriateRef.Value Like "(REF)*" Then
Me.Check66 = True
Else
Me.Check66 = False
End If
it behaved exactly as expected. I then moved it to the AfterUpdate event of the combobox, and again it worked flawlessly. The only thing I can see is that in your example, the combobox does not have the same name as your sub (ReasonForInappriopriateReferral vs RsnForInappropriateRef). Are you sure your names are right?

refresh vb6 form in background without losing user entered data

I'm working with some old VB6 code and have a scenario I'm trying to correct. I have a form that allows you to enter a person ID (use renters this in a textbox at the top) and click "show" it lists the appointment in the textbox on the same form. There is also a button that loads a new form that allows the user to edit the displayed data and save the change.
E.g. Change persons age from 65 to 64. I make this change, and save it. The save is successful and I unload the form to return to Form1. However, I must click "show" again to refresh the displayed data in the textbox to ensure the change is visible. I cannot figure out how to refresh this form, so the user doesn't have to click "show" to repopulate the textbox with the new value. Can anyone assist? I can't just create a new instance of Form1, because if I did that the person ID field would be blank.
Thanks!
Short version: How do I refresh a form to get latest data while still obtaining the relevant person ID.
There's not enough information here to answer your question. The general pattern you'd use in this situation is as follows:
SearchForm launches ViewForm.
ViewForm launches EditForm. When ViewForm constructs its instance of EditForm, it passes Me to EditForm (perhaps by setting EditForm.Parent).
When EditForm's Save button click event fires, it calls Parent.ReloadData (where Parent is the ViewForm that launched the EditForm).
Here is the approach that should work. In the editor have a public property that returns whether the form was cancelled or not. (.Cancelled). You'll have an object that carries attributes of the person that you are trying to change the age of. Then it's pretty simple. Code in the main form:
dim oPerson as clsPerson
dim oFrm as frmAgeEditor
set oPerson = GetCurrentPerson()
set oFrm = new frmAgeEditor
with oFrm
set .Person = oPerson
.Show vbModal
if not .Cancelled then
' Update Main form with the contents of oPerson
end if
end with
You can just call in "Show" function right after updating.
Call Me.frmParent.Refresh
I used this to refresh the screen without losing data.
I had to dig through a lot of old code to figure it out. This section had been written a long time ago, and worked well.
Public Sub Refresh()
Call cmdDetails_Click
If tvwScreeningSchedule.Nodes.Count > 0 Then
tvwScreeningSchedule.SelectedItem = tvwScreeningSchedule.Nodes(1)
Call tvwScreeningSchedule_Click
End If
End Sub
It's quite a specific function, and "cmdDetails_Click" contains alot of custom validation, but it's not too dis-similar to AngryHackers answer.