Loop Through and Clear Textfields

I did some searching through the forum and found some code for enabling/disabling textfields, but there seem to be some deprecated calls in it.

I want to loop through and clear out the text from my WebTextFields. Those WebTextFields are in a couple different WebRectangles I’m using as control groups (there are various controls in each, not just WebTextFields.

Here’s what I’ve got:

//HomePage is the page I'm working with
//InfoContainer1 is a WebContainer I've imbedded in HomePage

Var i As Integer
Var c As myTextField //Custom WebTextField I've added some properties to

for i = 0 to HomePage.InfoContainer1.LastControlIndex
  if HomePage.InfoContainer1.ControlAt(i) isa myTextField then
    c = StudentPageTextField(self.ControlAt(i))
  end if

The good news is that it doesn’t crash anything . . . The bad news is that it also doesn’t seem to do anything. If I put in a message box with i it doesn’t give the right number of controls.

Suggestions? Better solutions? (I mean, any solution is a better solution LOL)



that should look same the row above.
Use break points and system.debuglog as help.

Good catch! Thank you!

That ALMOST does it. I didn’t show in the code, but I’ve got controls grouped in a WebRectangle. I can the MyTextFields in the WebContainer, but when I go one deeper HomePage.InfoContainer1.MyControlsAreInThisWebRectangle.ControlAt(i) isa myTextField
then it doesn’t seem to find them at all (if I do a message with i’s value it’s -1).

I have a Feedback Case open on WebRectangle or more generally speaking with embedded controls: <https://xojo.com/issue/62709>

Wouldn’t be surprised that this affects as well changes you try via coding.

Thank for that. I was just going over this again this morning, as it’s annoying me to no end.

As MarkusR pointed out I had some sloppy coding (mostly because instead of just copy/pasting I tried to make it more generic for easier reading), and that solved the problem as long as it’s not in an embedded control.

I opened a new web project, subclassed WebTextField to MyWebTextField (which was probably unnecessary, but whatever), put a few MyWebTextFields into the main webpage and put the following into a PushButton:

Var i As Integer
Var c As myWebTextField //Custom WebTextField I've added some properties to

for i = 0 to self.LastControlIndex
  if self.ControlAt(i) isa myWebTextField then
    c = myWebTextField(self.ControlAt(i))
  end if

That works without a hitch.

If I add a WebRectangle (Rectangle1), add some MyWebTextFields to that and try to do the same thing:

Var j As Integer
Var d As myWebTextField //Custom WebTextField I've added some properties to

for j = 0 to Rectangle1.LastControlIndex
  if Rectangle1.ControlAt(j) isa myWebTextField then
    d = myWebTextField(Rectangle1.ControlAt(j))
    d.Text="I'm Inside the Rectangle"
  end if

It no longer works.

For now, thank you MarkusR for steering me back in the right direction, and thank you, Jeannot for pointing me to the Feedback case. Looks like another “Be patient and wait for a fix” scenario. :slight_smile:

Most likely yes but again I’m not sure. I just stopped using them as Xojo confirms that it is reproducible. This hurts and I’m impatient but I won’t waste my time until it is fixed :-).

1 Like

i tested it seems to be a bug but i have a workaround solution / concept

define a event in your control myWebTextField

Event RegisterMe()

for different controls add a interface with a clear method
select this interface in your class myWebTextField and fill method

Public Sub Clear()
  // Part of the Interface1 interface.
  Me.Text = "Clear" 
End Sub

add a property to memory all this controls in the WebPage

Public Property List() as Interface1

at the control in page add this event

Sub RegisterMe() Handles RegisterMe
  List.Add Me
End Sub

in the opening at myWebTextField

Sub Opening() Handles Opening
  RaiseEvent RegisterMe
End Sub

if you need to clear all use

For Each c As Interface1 In List